Skip to content

Commit e0b8ada

Browse files
authored
Merge pull request #284 from sheimi/prompt-to-mgit
Show dialog to prompt to upgrade to MGit
2 parents 8c8e7bd + 3690aa8 commit e0b8ada

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

src/main/java/me/sheimi/android/utils/Profile.java

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
public class Profile {
1616

17+
private static final String PREF_KEY_UPGRADE_SHOWN_COUNT = "pref_upgrade_shown_count";
1718
private static SharedPreferences sSharedPreference;
1819

1920
private static boolean sHasLastCloneFail = false;
@@ -77,6 +78,17 @@ public static int getStyledResource(Context context, int unstyled) {
7778
a.recycle();
7879
return styled;
7980
}
81+
82+
/**
83+
* Increment the number of times shown and return result
84+
* @param context
85+
* @return
86+
*/
87+
public static int incUpgradeMesssageShownCount(Context context) {
88+
int count = getProfileSharedPreference(context).getInt(PREF_KEY_UPGRADE_SHOWN_COUNT, 0);
89+
getProfileSharedPreference(context).edit().putInt(PREF_KEY_UPGRADE_SHOWN_COUNT, ++count).commit();
90+
return count;
91+
}
8092
}
8193

8294

src/main/java/me/sheimi/sgit/RepoListActivity.java

+66
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@
22

33
import android.app.Activity;
44
import android.app.AlertDialog;
5+
import android.content.ActivityNotFoundException;
56
import android.content.DialogInterface;
67
import android.content.Intent;
8+
import android.net.Uri;
79
import android.os.Bundle;
10+
import android.util.Log;
811
import android.view.Menu;
912
import android.view.MenuItem;
1013
import android.widget.ListView;
1114
import android.widget.SearchView;
1215

16+
import org.slf4j.helpers.Util;
17+
1318
import java.io.File;
1419

1520
import me.sheimi.android.activities.SheimiFragmentActivity;
21+
import me.sheimi.android.utils.FsUtils;
22+
import me.sheimi.android.utils.Profile;
1623
import me.sheimi.sgit.activities.UserSettingsActivity;
1724
import me.sheimi.sgit.activities.explorer.ExploreFileActivity;
1825
import me.sheimi.sgit.activities.explorer.ImportRepositoryActivity;
@@ -25,6 +32,8 @@
2532

2633
public class RepoListActivity extends SheimiFragmentActivity {
2734

35+
private static final String LOGTAG = RepoListActivity.class.getSimpleName();
36+
private static final int MAX_UPGRADE_SHOW_TIMES = 4;
2837
private ListView mRepoList;
2938
private RepoListAdapter mRepoListAdapter;
3039

@@ -41,6 +50,8 @@ protected void onCreate(Bundle savedInstanceState) {
4150
mRepoListAdapter.queryAllRepo();
4251
mRepoList.setOnItemClickListener(mRepoListAdapter);
4352
mRepoList.setOnItemLongClickListener(mRepoListAdapter);
53+
54+
showUpgradeDialog();
4455
}
4556

4657
@Override
@@ -151,4 +162,59 @@ public void finish() {
151162
rawfinish();
152163
}
153164

165+
// Prompt user to install MGit as SGit is no longer being maintained
166+
private void showUpgradeDialog() {
167+
168+
if (Profile.incUpgradeMesssageShownCount(getApplicationContext()) > MAX_UPGRADE_SHOW_TIMES) {
169+
return;
170+
}
171+
172+
File repoLocation = FsUtils.getRepoDir(getApplicationContext(),"");
173+
String mesg = getString(R.string.dialog_upgrade_message,
174+
(repoLocation != null) ? repoLocation.toString() : getString(R.string.default_repo_path));
175+
176+
new AlertDialog.Builder(this)
177+
.setMessage(mesg)
178+
.setPositiveButton(getString(R.string.dialog_upgrade_ok_button), new DialogInterface.OnClickListener() {
179+
@Override
180+
public void onClick(DialogInterface dialog, int which) {
181+
Intent goToMarket = new Intent(Intent.ACTION_VIEW)
182+
.setData(Uri.parse("market://details?id=com.manichord.mgit"));
183+
try {
184+
startActivity(goToMarket);
185+
} catch (ActivityNotFoundException e) {
186+
dialog.dismiss();
187+
showNoGooglePlayDialog();
188+
}
189+
}
190+
})
191+
.setNegativeButton(getString(R.string.dialog_upgrade_cancel_button), new DialogInterface.OnClickListener() {
192+
public void onClick(DialogInterface dialog,int id) {
193+
dialog.cancel();
194+
}
195+
})
196+
.create().show();
197+
}
198+
199+
private void showNoGooglePlayDialog() {
200+
AlertDialog.Builder builder = new AlertDialog.Builder(RepoListActivity.this);
201+
builder.setMessage(getString(R.string.sorry_play_missing_message));
202+
builder.setPositiveButton(getString(R.string.dialog_goto_github_ok_button), new DialogInterface.OnClickListener() {
203+
@Override
204+
public void onClick(DialogInterface dialog, int which) {
205+
Intent goToGithub = new Intent(Intent.ACTION_VIEW)
206+
.setData(Uri.parse("https://github.com/maks/MGit/releases"));
207+
try {
208+
startActivity(goToGithub);
209+
} catch (ActivityNotFoundException e) {
210+
Log.e(LOGTAG, "could not show Github url for MGit", e);
211+
}
212+
}
213+
})
214+
.setNegativeButton(getString(R.string.dialog_upgrade_cancel_button), new DialogInterface.OnClickListener() {
215+
public void onClick(DialogInterface dialog,int id) {
216+
dialog.cancel();
217+
}
218+
}).create().show();
219+
}
154220
}

src/main/java/me/sheimi/sgit/activities/RepoDetailActivity.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package me.sheimi.sgit.activities;
22

33
import android.app.ActionBar;
4+
import android.app.AlertDialog;
45
import android.app.FragmentManager;
6+
import android.content.DialogInterface;
57
import android.content.Intent;
68
import android.os.Bundle;
79
import android.support.v13.app.FragmentPagerAdapter;

src/main/res/values/strings.xml

+11
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,15 @@
167167
<string name="action_git_profile">Git Profile</string>
168168
<string name="action_open_in_other_app">Open in other apps</string>
169169
<string name="action_add_private_key">Add Private Key</string>
170+
<string name="dialog_upgrade_title">Upgrade To MGit</string>
171+
<string name="dialog_upgrade_message">SGit is no longer being developed. Please install MGit which continues development of this app with new features and bug fixes.
172+
\n\nPlease note your Repos are currently stored in:\n
173+
%s
174+
\n\nMGit may NOT be set to use this location by default, it can be set in MGit settings after you have installed it.
175+
</string>
176+
<string name="dialog_upgrade_ok_button">Install MGit</string>
177+
<string name="dialog_upgrade_cancel_button">Cancel</string>
178+
<string name="default_repo_path">[sdcard dir]/Android/data/me.sheimi.sgit/files/repo</string>
179+
<string name="sorry_play_missing_message">Sorry you do not have Google Play installed. You can install the latest MGit release directly using the APK for Github.</string>
180+
<string name="dialog_goto_github_ok_button">Goto Github</string>
170181
</resources>

0 commit comments

Comments
 (0)