Browse Source
Merge branch 'master' into retrofit-intercept-errors
renovate/org.robolectric-robolectric-4.x
Merge branch 'master' into retrofit-intercept-errors
renovate/org.robolectric-robolectric-4.x
Austin Huang
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 654 additions and 264 deletions
-
3app/build.gradle
-
64app/src/fdroid/java/awais/instagrabber/utils/UpdateChecker.java
-
61app/src/github/java/awais/instagrabber/utils/UpdateChecker.java
-
3app/src/main/AndroidManifest.xml
-
3app/src/main/java/awais/instagrabber/activities/MainActivity.java
-
14app/src/main/java/awais/instagrabber/dialogs/AccountSwitcherDialogFragment.java
-
11app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java
-
74app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
-
10app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java
-
9app/src/main/java/awais/instagrabber/fragments/settings/DownloadsPreferencesFragment.java
-
37app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java
-
8app/src/main/java/awais/instagrabber/fragments/settings/StoriesPreferencesFragment.java
-
3app/src/main/java/awais/instagrabber/utils/Constants.java
-
82app/src/main/java/awais/instagrabber/utils/DownloadUtils.java
-
17app/src/main/java/awais/instagrabber/utils/ExportImportUtils.java
-
118app/src/main/java/awais/instagrabber/utils/FlavorTown.java
-
111app/src/main/java/awais/instagrabber/utils/ProcessPhoenix.java
-
12app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java
-
6app/src/main/java/awais/instagrabber/utils/SettingsHelper.java
-
38app/src/main/java/awais/instagrabber/utils/UpdateCheckCommon.java
-
58app/src/main/java/awais/instagrabber/utils/UpdateChecker.java
-
8app/src/main/java/awais/instagrabber/utils/Utils.java
-
8app/src/main/java/awais/instagrabber/webservices/NewsService.java
-
35app/src/main/java/awais/instagrabber/webservices/StoriesService.java
-
1app/src/main/res/layout/layout_profile_details.xml
-
13app/src/main/res/menu/story_menu.xml
-
43app/src/main/res/navigation/notification_viewer_nav_graph.xml
-
20app/src/main/res/navigation/profile_nav_graph.xml
-
1app/src/main/res/values-ca/strings.xml
-
1app/src/main/res/values-cs/strings.xml
-
1app/src/main/res/values-de/strings.xml
-
1app/src/main/res/values-el/strings.xml
-
1app/src/main/res/values-es/strings.xml
-
1app/src/main/res/values-eu/strings.xml
-
1app/src/main/res/values-fa/strings.xml
-
1app/src/main/res/values-fr/strings.xml
-
1app/src/main/res/values-hi/strings.xml
-
1app/src/main/res/values-in/strings.xml
-
1app/src/main/res/values-it/strings.xml
-
1app/src/main/res/values-ja/strings.xml
-
1app/src/main/res/values-kn/strings.xml
-
1app/src/main/res/values-mk/strings.xml
-
1app/src/main/res/values-nl/strings.xml
-
1app/src/main/res/values-or/strings.xml
-
1app/src/main/res/values-pl/strings.xml
-
1app/src/main/res/values-pt/strings.xml
-
1app/src/main/res/values-ru/strings.xml
-
1app/src/main/res/values-sk/strings.xml
-
1app/src/main/res/values-tr/strings.xml
-
1app/src/main/res/values-vi/strings.xml
-
1app/src/main/res/values-zh-rCN/strings.xml
-
1app/src/main/res/values-zh-rTW/strings.xml
-
4app/src/main/res/values/strings.xml
-
1app/src/main/resources/feed_response.json
-
1app/src/main/resources/stories_response.json
@ -0,0 +1,64 @@ |
|||
package awais.instagrabber.utils; |
|||
|
|||
import android.util.Log; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.annotation.Nullable; |
|||
import androidx.appcompat.app.AppCompatActivity; |
|||
|
|||
import org.json.JSONObject; |
|||
|
|||
import java.net.HttpURLConnection; |
|||
import java.net.URL; |
|||
|
|||
public class UpdateChecker { |
|||
private static final Object LOCK = new Object(); |
|||
private static final String TAG = UpdateChecker.class.getSimpleName(); |
|||
|
|||
private static UpdateChecker instance; |
|||
|
|||
public static UpdateChecker getInstance() { |
|||
if (instance == null) { |
|||
synchronized (LOCK) { |
|||
if (instance == null) { |
|||
instance = new UpdateChecker(); |
|||
} |
|||
} |
|||
} |
|||
return instance; |
|||
} |
|||
|
|||
/** |
|||
* Needs to be called asynchronously |
|||
* |
|||
* @return the latest version from f-droid |
|||
*/ |
|||
@Nullable |
|||
public String getLatestVersion() { |
|||
HttpURLConnection conn = null; |
|||
try { |
|||
conn = (HttpURLConnection) new URL("https://f-droid.org/api/v1/packages/me.austinhuang.instagrabber").openConnection(); |
|||
conn.setUseCaches(false); |
|||
conn.setRequestProperty("User-Agent", "https://Barinsta.AustinHuang.me / mailto:[email protected]"); |
|||
conn.connect(); |
|||
final int responseCode = conn.getResponseCode(); |
|||
if (responseCode == HttpURLConnection.HTTP_OK) { |
|||
final JSONObject data = new JSONObject(NetworkUtils.readFromConnection(conn)); |
|||
return "v" + data.getJSONArray("packages").getJSONObject(0).getString("versionName"); |
|||
// if (BuildConfig.VERSION_CODE < data.getInt("suggestedVersionCode")) { |
|||
// } |
|||
} |
|||
} catch (final Exception e) { |
|||
Log.e(TAG, "", e); |
|||
} finally { |
|||
if (conn != null) { |
|||
conn.disconnect(); |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public void onDownload(@NonNull final AppCompatActivity context) { |
|||
Utils.openURL(context, "https://f-droid.org/packages/me.austinhuang.instagrabber/"); |
|||
} |
|||
} |
@ -0,0 +1,61 @@ |
|||
package awais.instagrabber.utils; |
|||
|
|||
import android.content.Context; |
|||
import android.util.Log; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.annotation.Nullable; |
|||
|
|||
import java.net.HttpURLConnection; |
|||
import java.net.URL; |
|||
|
|||
public class UpdateChecker { |
|||
private static final Object LOCK = new Object(); |
|||
private static final String TAG = UpdateChecker.class.getSimpleName(); |
|||
|
|||
private static UpdateChecker instance; |
|||
|
|||
public static UpdateChecker getInstance() { |
|||
if (instance == null) { |
|||
synchronized (LOCK) { |
|||
if (instance == null) { |
|||
instance = new UpdateChecker(); |
|||
} |
|||
} |
|||
} |
|||
return instance; |
|||
} |
|||
|
|||
/** |
|||
* Needs to be called asynchronously |
|||
* |
|||
* @return the latest version from Github |
|||
*/ |
|||
@Nullable |
|||
public String getLatestVersion() { |
|||
HttpURLConnection conn = null; |
|||
try { |
|||
conn = (HttpURLConnection) new URL("https://github.com/austinhuang0131/barinsta/releases/latest").openConnection(); |
|||
conn.setInstanceFollowRedirects(false); |
|||
conn.setUseCaches(false); |
|||
conn.setRequestProperty("User-Agent", "https://Barinsta.AustinHuang.me / mailto:[email protected]"); |
|||
conn.connect(); |
|||
final int responseCode = conn.getResponseCode(); |
|||
if (responseCode == HttpURLConnection.HTTP_MOVED_TEMP) { |
|||
return "v" + conn.getHeaderField("Location").split("/v")[1]; |
|||
// return !version.equals(BuildConfig.VERSION_NAME); |
|||
} |
|||
} catch (final Exception e) { |
|||
Log.e(TAG, "", e); |
|||
} finally { |
|||
if (conn != null) { |
|||
conn.disconnect(); |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public void onDownload(@NonNull final Context context) { |
|||
Utils.openURL(context, "https://github.com/austinhuang0131/instagrabber/releases/latest"); |
|||
} |
|||
} |
@ -0,0 +1,111 @@ |
|||
/* |
|||
* Copyright (C) 2014 Jake Wharton |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package awais.instagrabber.utils; |
|||
|
|||
import android.app.Activity; |
|||
import android.app.ActivityManager; |
|||
import android.content.Context; |
|||
import android.content.Intent; |
|||
import android.os.Bundle; |
|||
import android.os.Process; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
|
|||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK; |
|||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
|||
|
|||
/** |
|||
* Process Phoenix facilitates restarting your application process. This should only be used for |
|||
* things like fundamental state changes in your debug builds (e.g., changing from staging to |
|||
* production). |
|||
* <p> |
|||
* Trigger process recreation by calling {@link #triggerRebirth} with a {@link Context} instance. |
|||
*/ |
|||
public final class ProcessPhoenix extends Activity { |
|||
private static final String KEY_RESTART_INTENTS = "phoenix_restart_intents"; |
|||
|
|||
/** |
|||
* Call to restart the application process using the {@linkplain Intent#CATEGORY_DEFAULT default} |
|||
* activity as an intent. |
|||
* <p> |
|||
* Behavior of the current process after invoking this method is undefined. |
|||
*/ |
|||
public static void triggerRebirth(Context context) { |
|||
triggerRebirth(context, getRestartIntent(context)); |
|||
} |
|||
|
|||
/** |
|||
* Call to restart the application process using the specified intents. |
|||
* <p> |
|||
* Behavior of the current process after invoking this method is undefined. |
|||
*/ |
|||
public static void triggerRebirth(Context context, Intent... nextIntents) { |
|||
Intent intent = new Intent(context, ProcessPhoenix.class); |
|||
intent.addFlags(FLAG_ACTIVITY_NEW_TASK); // In case we are called with non-Activity context. |
|||
intent.putParcelableArrayListExtra(KEY_RESTART_INTENTS, new ArrayList<>(Arrays.asList(nextIntents))); |
|||
context.startActivity(intent); |
|||
if (context instanceof Activity) { |
|||
((Activity) context).finish(); |
|||
} |
|||
Runtime.getRuntime().exit(0); // Kill kill kill! |
|||
} |
|||
|
|||
private static Intent getRestartIntent(Context context) { |
|||
String packageName = context.getPackageName(); |
|||
Intent defaultIntent = context.getPackageManager().getLaunchIntentForPackage(packageName); |
|||
if (defaultIntent != null) { |
|||
defaultIntent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK); |
|||
return defaultIntent; |
|||
} |
|||
|
|||
throw new IllegalStateException("Unable to determine default activity for " |
|||
+ packageName |
|||
+ ". Does an activity specify the DEFAULT category in its intent filter?"); |
|||
} |
|||
|
|||
@Override |
|||
protected void onCreate(Bundle savedInstanceState) { |
|||
super.onCreate(savedInstanceState); |
|||
|
|||
ArrayList<Intent> intents = getIntent().getParcelableArrayListExtra(KEY_RESTART_INTENTS); |
|||
startActivities(intents.toArray(new Intent[intents.size()])); |
|||
finish(); |
|||
Runtime.getRuntime().exit(0); // Kill kill kill! |
|||
} |
|||
|
|||
/** |
|||
* Checks if the current process is a temporary Phoenix Process. |
|||
* This can be used to avoid initialisation of unused resources or to prevent running code that |
|||
* is not multi-process ready. |
|||
* |
|||
* @return true if the current process is a temporary Phoenix Process |
|||
*/ |
|||
public static boolean isPhoenixProcess(Context context) { |
|||
int currentPid = Process.myPid(); |
|||
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|||
List<ActivityManager.RunningAppProcessInfo> runningProcesses = manager.getRunningAppProcesses(); |
|||
if (runningProcesses != null) { |
|||
for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) { |
|||
if (processInfo.pid == currentPid && processInfo.processName.endsWith(":phoenix")) { |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
} |
@ -0,0 +1,38 @@ |
|||
package awais.instagrabber.utils; |
|||
|
|||
import android.content.Context; |
|||
import android.content.DialogInterface; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
|
|||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
|||
|
|||
import awais.instagrabber.BuildConfig; |
|||
import awais.instagrabber.R; |
|||
|
|||
import static awais.instagrabber.utils.Utils.settingsHelper; |
|||
|
|||
public final class UpdateCheckCommon { |
|||
|
|||
public static boolean shouldShowUpdateDialog(final boolean force, |
|||
@NonNull final String version) { |
|||
final String skippedVersion = settingsHelper.getString(Constants.SKIPPED_VERSION); |
|||
return force || (!BuildConfig.DEBUG && !skippedVersion.equals(version)); |
|||
} |
|||
|
|||
public static void showUpdateDialog(@NonNull final Context context, |
|||
@NonNull final String version, |
|||
@NonNull final DialogInterface.OnClickListener onDownloadClickListener) { |
|||
AppExecutors.getInstance().mainThread().execute(() -> { |
|||
new MaterialAlertDialogBuilder(context) |
|||
.setTitle(context.getString(R.string.update_available, version)) |
|||
.setNeutralButton(R.string.skip_update, (dialog, which) -> { |
|||
settingsHelper.putString(Constants.SKIPPED_VERSION, version); |
|||
dialog.dismiss(); |
|||
}) |
|||
.setPositiveButton(R.string.action_download, onDownloadClickListener) |
|||
.setNegativeButton(R.string.cancel, null) |
|||
.show(); |
|||
}); |
|||
} |
|||
} |
@ -1,58 +0,0 @@ |
|||
package awais.instagrabber.utils; |
|||
|
|||
import android.os.AsyncTask; |
|||
import android.util.Log; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
|
|||
import org.json.JSONObject; |
|||
|
|||
import java.net.HttpURLConnection; |
|||
import java.net.URL; |
|||
|
|||
import awais.instagrabber.BuildConfig; |
|||
import awais.instagrabber.interfaces.FetchListener; |
|||
|
|||
public final class UpdateChecker extends AsyncTask<Void, Void, Boolean> { |
|||
private final FetchListener<String> fetchListener; |
|||
private String version; |
|||
|
|||
public UpdateChecker(final FetchListener<String> fetchListener) { |
|||
this.fetchListener = fetchListener; |
|||
} |
|||
|
|||
@NonNull |
|||
@Override |
|||
protected Boolean doInBackground(final Void... voids) { |
|||
try { |
|||
version = ""; |
|||
|
|||
HttpURLConnection conn = |
|||
(HttpURLConnection) new URL("https://f-droid.org/api/v1/packages/me.austinhuang.instagrabber").openConnection(); |
|||
conn.setUseCaches(false); |
|||
conn.setRequestProperty("User-Agent", "https://Barinsta.AustinHuang.me / mailto:[email protected]"); |
|||
conn.connect(); |
|||
|
|||
final int responseCode = conn.getResponseCode(); |
|||
if (responseCode == HttpURLConnection.HTTP_OK) { |
|||
final JSONObject data = new JSONObject(NetworkUtils.readFromConnection(conn)); |
|||
if (BuildConfig.VERSION_CODE < data.getInt("suggestedVersionCode")) { |
|||
version = data.getJSONArray("packages").getJSONObject(0).getString("versionName"); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
conn.disconnect(); |
|||
} catch (final Exception e) { |
|||
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
@Override |
|||
protected void onPostExecute(final Boolean result) { |
|||
if (result != null && result && fetchListener != null) |
|||
fetchListener.onResult("v"+version); |
|||
} |
|||
} |
@ -1 +0,0 @@ |
|||
{} |
@ -1 +0,0 @@ |
|||
{} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue