mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-01-22 22:08:08 -05:00
Extract open link handler
This commit is contained in:
@@ -12,6 +12,11 @@ import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.collection.ArrayMap;
|
||||
import androidx.core.text.HtmlCompat;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -20,10 +25,6 @@ import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.core.text.HtmlCompat;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
||||
import protect.card_locker.databinding.AboutActivityBinding;
|
||||
|
||||
public class AboutActivity extends CatimaAppCompatActivity {
|
||||
@@ -67,7 +68,7 @@ public class AboutActivity extends CatimaAppCompatActivity {
|
||||
}
|
||||
|
||||
private void bindClickListeners() {
|
||||
View.OnClickListener openExternalBrowser = createOpenExternalBrowserClickListener();
|
||||
View.OnClickListener openExternalBrowser = view -> (new AboutOpenLinkHandler()).open(this, view);
|
||||
|
||||
binding.versionHistory.setOnClickListener(openExternalBrowser);
|
||||
binding.translate.setOnClickListener(openExternalBrowser);
|
||||
@@ -97,40 +98,6 @@ public class AboutActivity extends CatimaAppCompatActivity {
|
||||
binding.credits.setOnClickListener(null);
|
||||
}
|
||||
|
||||
private View.OnClickListener createOpenExternalBrowserClickListener() {
|
||||
return (View view) -> {
|
||||
int id = view.getId();
|
||||
|
||||
String url;
|
||||
if (id == R.id.version_history) {
|
||||
url = "https://catima.app/changelog/";
|
||||
} else if (id == R.id.translate) {
|
||||
url = "https://hosted.weblate.org/engage/catima/";
|
||||
} else if (id == R.id.license) {
|
||||
url = "https://github.com/CatimaLoyalty/Android/blob/master/LICENSE";
|
||||
} else if (id == R.id.repo) {
|
||||
url = "https://github.com/CatimaLoyalty/Android/";
|
||||
} else if (id == R.id.privacy) {
|
||||
url = "https://catima.app/privacy-policy/";
|
||||
} else if (id == R.id.report_error) {
|
||||
url = "https://github.com/CatimaLoyalty/Android/issues";
|
||||
} else if (id == R.id.rate) {
|
||||
url = "https://play.google.com/store/apps/details?id=me.hackerchick.catima";
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
try {
|
||||
startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(this, R.string.failedToOpenUrl, Toast.LENGTH_LONG).show();
|
||||
Log.e(TAG, "No activity found to handle intent", e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private String getAppVersion() {
|
||||
String version = "?";
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user