mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-04-02 14:51:43 -04:00
Remove map from id to link. make link handler more solid
This commit is contained in:
@@ -27,12 +27,19 @@ public class AboutActivity extends CatimaAppCompatActivity {
|
||||
setSupportActionBar(binding.toolbar);
|
||||
enableToolbarBackButton();
|
||||
|
||||
|
||||
TextView copyright = binding.creditsSub;
|
||||
copyright.setText(content.getCopyright());
|
||||
TextView versionHistory = binding.versionHistorySub;
|
||||
versionHistory.setText(content.getVersionHistory());
|
||||
|
||||
binding.versionHistory.setTag("https://catima.app/changelog/");
|
||||
binding.translate.setTag("https://hosted.weblate.org/engage/catima/");
|
||||
binding.license.setTag("https://github.com/CatimaLoyalty/Android/blob/master/LICENSE");
|
||||
binding.repo.setTag("https://github.com/CatimaLoyalty/Android/");
|
||||
binding.privacy.setTag("https://catima.app/privacy-policy/");
|
||||
binding.reportError.setTag("https://github.com/CatimaLoyalty/Android/issues");
|
||||
binding.rate.setTag("https://play.google.com/store/apps/details?id=me.hackerchick.catima");
|
||||
|
||||
bindClickListeners();
|
||||
}
|
||||
|
||||
@@ -54,8 +61,12 @@ public class AboutActivity extends CatimaAppCompatActivity {
|
||||
}
|
||||
|
||||
private void bindClickListeners() {
|
||||
View.OnClickListener openExternalBrowser = view -> (new AboutOpenLinkHandler()).open(this, view);
|
||||
|
||||
View.OnClickListener openExternalBrowser = view -> {
|
||||
Object tag = view.getTag();
|
||||
if (tag instanceof String && ((String) tag).startsWith("https://")) {
|
||||
(new OpenWebLinkHandler()).open(this, (String) tag);
|
||||
}
|
||||
};
|
||||
binding.versionHistory.setOnClickListener(openExternalBrowser);
|
||||
binding.translate.setOnClickListener(openExternalBrowser);
|
||||
binding.license.setOnClickListener(openExternalBrowser);
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package protect.card_locker;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.collection.ArrayMap;
|
||||
|
||||
public class AboutOpenLinkHandler {
|
||||
|
||||
private static final String TAG = "Catima";
|
||||
|
||||
private final ArrayMap<Integer, String> viewIdToUrlMap = new ArrayMap<Integer, String>();
|
||||
|
||||
AboutOpenLinkHandler() {
|
||||
viewIdToUrlMap.put(R.id.version_history, "https://catima.app/changelog/");
|
||||
viewIdToUrlMap.put(R.id.translate, "https://hosted.weblate.org/engage/catima/");
|
||||
viewIdToUrlMap.put(R.id.license, "https://github.com/CatimaLoyalty/Android/blob/master/LICENSE");
|
||||
viewIdToUrlMap.put(R.id.repo, "https://github.com/CatimaLoyalty/Android/");
|
||||
viewIdToUrlMap.put(R.id.privacy, "https://catima.app/privacy-policy/");
|
||||
viewIdToUrlMap.put(R.id.report_error, "https://github.com/CatimaLoyalty/Android/issues");
|
||||
viewIdToUrlMap.put(R.id.rate, "https://play.google.com/store/apps/details?id=me.hackerchick.catima");
|
||||
}
|
||||
|
||||
public void open(AppCompatActivity activity, View view) {
|
||||
String url = viewIdToUrlMap.get(view.getId());
|
||||
if (url == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
try {
|
||||
activity.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(activity, R.string.failedToOpenUrl, Toast.LENGTH_LONG).show();
|
||||
Log.e(TAG, "No activity found to handle intent", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package protect.card_locker;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public class OpenWebLinkHandler {
|
||||
|
||||
private static final String TAG = "Catima";
|
||||
|
||||
public void open(AppCompatActivity activity, String url) {
|
||||
if (url == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
try {
|
||||
activity.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(activity, R.string.failedToOpenUrl, Toast.LENGTH_LONG).show();
|
||||
Log.e(TAG, "No activity found to handle intent", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user