|
3 | 3 | import android.content.ComponentName; |
4 | 4 | import android.content.Intent; |
5 | 5 | import android.content.pm.ApplicationInfo; |
| 6 | +import android.content.pm.PackageInfo; |
6 | 7 | import android.content.pm.PackageManager; |
| 8 | +import android.graphics.drawable.Drawable; |
| 9 | +import android.net.Uri; |
7 | 10 | import android.os.Bundle; |
8 | 11 | import android.view.View; |
9 | 12 | import android.view.animation.Animation; |
|
12 | 15 |
|
13 | 16 | import androidx.annotation.NonNull; |
14 | 17 | import androidx.appcompat.app.AppCompatActivity; |
| 18 | +import androidx.appcompat.content.res.AppCompatResources; |
15 | 19 | import androidx.core.widget.NestedScrollView; |
16 | 20 | import androidx.recyclerview.widget.LinearLayoutManager; |
17 | 21 | import androidx.recyclerview.widget.RecyclerView; |
18 | 22 |
|
19 | 23 | import com.sjapps.jsonlist.R; |
| 24 | +import com.sjapps.library.customdialog.ImageListItem; |
| 25 | +import com.sjapps.library.customdialog.ListDialog; |
20 | 26 |
|
21 | 27 | import java.util.ArrayList; |
22 | 28 |
|
23 | 29 | public class AboutActivity extends AppCompatActivity { |
24 | 30 |
|
| 31 | + private static final String GITHUB_REPOSITORY_RELEASES = "https://github.com/SlaVcE14/JsonList/releases"; |
25 | 32 | final String STORE_PACKAGE_NAME = "com.sjapps.sjstore"; |
26 | 33 |
|
27 | 34 | ImageView logo; |
28 | 35 | NestedScrollView nestedScrollView; |
29 | 36 | RecyclerView ListRV,LibListRV; |
30 | 37 | ArrayList<AboutListItem> appInfoItems = new ArrayList<>(); |
31 | 38 | ArrayList<AboutListItem> libsItems; |
| 39 | + boolean isStoreInstalled; |
| 40 | + Drawable storeIcon; |
32 | 41 |
|
33 | 42 | @Override |
34 | 43 | protected void onCreate(Bundle savedInstanceState) { |
@@ -69,24 +78,53 @@ void initialize(){ |
69 | 78 | ListRV = findViewById(R.id.aboutList); |
70 | 79 | LibListRV = findViewById(R.id.LibrariesList); |
71 | 80 | nestedScrollView = findViewById(R.id.nestedList); |
72 | | - |
| 81 | + findViewById(R.id.updateBtn).setVisibility(View.VISIBLE); |
73 | 82 | if (CheckStoreIsInstalled()){ |
74 | | - findViewById(R.id.updateBtn).setVisibility(View.VISIBLE); |
| 83 | + isStoreInstalled = true; |
75 | 84 | } |
76 | 85 | } |
77 | 86 |
|
78 | 87 | public void CheckForUpdate(View view) { |
| 88 | + if (!isStoreInstalled) { |
| 89 | + openGitHub(); |
| 90 | + return; |
| 91 | + } |
| 92 | + |
| 93 | + ListDialog dialog = new ListDialog(); |
| 94 | + |
| 95 | + ArrayList<ImageListItem> items = new ArrayList<>(); |
| 96 | + items.add(new ImageListItem("GitHub", AppCompatResources.getDrawable(this,R.drawable.github_logo), (ImageItemClick) this::openGitHub)); |
| 97 | + items.add(new ImageListItem("SJ Store", storeIcon, (ImageItemClick) this::openStore)); |
| 98 | + |
| 99 | + dialog.Builder(this,true) |
| 100 | + .setTitle("Open...") |
| 101 | + .setImageItems(items, (position, obj) -> { |
| 102 | + if (obj.getData() == null) |
| 103 | + return; |
| 104 | + ((ImageItemClick) obj.getData()).onClick(); |
| 105 | + dialog.dismiss(); |
| 106 | + }) |
| 107 | + .show(); |
| 108 | + } |
| 109 | + |
| 110 | + private void openGitHub(){ |
| 111 | + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(GITHUB_REPOSITORY_RELEASES)); |
| 112 | + startActivity(intent); |
| 113 | + } |
| 114 | + |
| 115 | + private void openStore(){ |
79 | 116 | Intent intent = new Intent(); |
80 | 117 | intent.setComponent(new ComponentName(STORE_PACKAGE_NAME,STORE_PACKAGE_NAME + ".AppActivity")); |
81 | 118 | intent.putExtra("packageName", getPackageName()); |
82 | 119 | intent.putExtra("isInstalled",true); |
83 | 120 | startActivity(intent); |
84 | 121 | } |
85 | 122 |
|
86 | | - public boolean CheckStoreIsInstalled(){ |
| 123 | + private boolean CheckStoreIsInstalled(){ |
87 | 124 | PackageManager packageManager = getPackageManager(); |
88 | 125 | try { |
89 | | - packageManager.getPackageInfo(STORE_PACKAGE_NAME,0); |
| 126 | + PackageInfo packageInfo = packageManager.getPackageInfo(STORE_PACKAGE_NAME,0); |
| 127 | + storeIcon = packageInfo.applicationInfo.loadIcon(packageManager); |
90 | 128 | return true; |
91 | 129 | } catch (PackageManager.NameNotFoundException e) { |
92 | 130 | return false; |
|
0 commit comments