mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-16 19:57:31 +00:00
Add activity checker service
This commit is contained in:
parent
60d9e64a57
commit
08134ef5f1
@ -138,5 +138,6 @@
|
|||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
android:resource="@xml/provider_paths" />
|
android:resource="@xml/provider_paths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
<service android:name=".services.ActivityCheckerService" />
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
@ -4,7 +4,6 @@ import android.content.ClipboardManager;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.core.app.NotificationManagerCompat;
|
|
||||||
import androidx.multidex.MultiDexApplication;
|
import androidx.multidex.MultiDexApplication;
|
||||||
|
|
||||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||||
@ -26,7 +25,6 @@ import static awais.instagrabber.utils.Utils.clipboardManager;
|
|||||||
import static awais.instagrabber.utils.Utils.dataBox;
|
import static awais.instagrabber.utils.Utils.dataBox;
|
||||||
import static awais.instagrabber.utils.Utils.datetimeParser;
|
import static awais.instagrabber.utils.Utils.datetimeParser;
|
||||||
import static awais.instagrabber.utils.Utils.logCollector;
|
import static awais.instagrabber.utils.Utils.logCollector;
|
||||||
import static awais.instagrabber.utils.Utils.notificationManager;
|
|
||||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||||
|
|
||||||
public final class InstaGrabberApplication extends MultiDexApplication {
|
public final class InstaGrabberApplication extends MultiDexApplication {
|
||||||
@ -67,9 +65,6 @@ public final class InstaGrabberApplication extends MultiDexApplication {
|
|||||||
|
|
||||||
LocaleUtils.setLocale(getBaseContext());
|
LocaleUtils.setLocale(getBaseContext());
|
||||||
|
|
||||||
if (notificationManager == null)
|
|
||||||
notificationManager = NotificationManagerCompat.from(appContext);
|
|
||||||
|
|
||||||
if (clipboardManager == null)
|
if (clipboardManager == null)
|
||||||
clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
|
||||||
|
@ -2,13 +2,20 @@ package awais.instagrabber.activities;
|
|||||||
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.NotificationChannel;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.ServiceConnection;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.database.MatrixCursor;
|
import android.database.MatrixCursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.IBinder;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -21,10 +28,12 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.appcompat.widget.SearchView;
|
import androidx.appcompat.widget.SearchView;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.navigation.NavBackStackEntry;
|
import androidx.navigation.NavBackStackEntry;
|
||||||
import androidx.navigation.NavController;
|
import androidx.navigation.NavController;
|
||||||
import androidx.navigation.NavDestination;
|
import androidx.navigation.NavDestination;
|
||||||
|
import androidx.navigation.NavDirections;
|
||||||
import androidx.navigation.ui.NavigationUI;
|
import androidx.navigation.ui.NavigationUI;
|
||||||
|
|
||||||
import com.google.android.material.appbar.AppBarLayout;
|
import com.google.android.material.appbar.AppBarLayout;
|
||||||
@ -43,10 +52,12 @@ import awais.instagrabber.adapters.SuggestionsAdapter;
|
|||||||
import awais.instagrabber.asyncs.SuggestionsFetcher;
|
import awais.instagrabber.asyncs.SuggestionsFetcher;
|
||||||
import awais.instagrabber.customviews.helpers.CustomHideBottomViewOnScrollBehavior;
|
import awais.instagrabber.customviews.helpers.CustomHideBottomViewOnScrollBehavior;
|
||||||
import awais.instagrabber.databinding.ActivityMainBinding;
|
import awais.instagrabber.databinding.ActivityMainBinding;
|
||||||
|
import awais.instagrabber.fragments.settings.MorePreferencesFragmentDirections;
|
||||||
import awais.instagrabber.interfaces.FetchListener;
|
import awais.instagrabber.interfaces.FetchListener;
|
||||||
import awais.instagrabber.models.IntentModel;
|
import awais.instagrabber.models.IntentModel;
|
||||||
import awais.instagrabber.models.SuggestionModel;
|
import awais.instagrabber.models.SuggestionModel;
|
||||||
import awais.instagrabber.models.enums.SuggestionType;
|
import awais.instagrabber.models.enums.SuggestionType;
|
||||||
|
import awais.instagrabber.services.ActivityCheckerService;
|
||||||
import awais.instagrabber.utils.Constants;
|
import awais.instagrabber.utils.Constants;
|
||||||
import awais.instagrabber.utils.CookieUtils;
|
import awais.instagrabber.utils.CookieUtils;
|
||||||
import awais.instagrabber.utils.FlavorTown;
|
import awais.instagrabber.utils.FlavorTown;
|
||||||
@ -93,7 +104,21 @@ public class MainActivity extends BaseLanguageActivity {
|
|||||||
private boolean showSearch = true;
|
private boolean showSearch = true;
|
||||||
private Handler suggestionsFetchHandler;
|
private Handler suggestionsFetchHandler;
|
||||||
private int firstFragmentGraphIndex;
|
private int firstFragmentGraphIndex;
|
||||||
private boolean isLoggedIn;
|
private boolean isActivityCheckerServiceBound = false;
|
||||||
|
|
||||||
|
private final ServiceConnection serviceConnection = new ServiceConnection() {
|
||||||
|
@Override
|
||||||
|
public void onServiceConnected(final ComponentName name, final IBinder service) {
|
||||||
|
// final ActivityCheckerService.LocalBinder binder = (ActivityCheckerService.LocalBinder) service;
|
||||||
|
// final ActivityCheckerService activityCheckerService = binder.getService();
|
||||||
|
isActivityCheckerServiceBound = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceDisconnected(final ComponentName name) {
|
||||||
|
isActivityCheckerServiceBound = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static {
|
static {
|
||||||
NAV_TO_MENU_ID_MAP.put(R.navigation.direct_messages_nav_graph, R.id.direct_messages_nav_graph);
|
NAV_TO_MENU_ID_MAP.put(R.navigation.direct_messages_nav_graph, R.id.direct_messages_nav_graph);
|
||||||
@ -112,6 +137,7 @@ public class MainActivity extends BaseLanguageActivity {
|
|||||||
setContentView(binding.getRoot());
|
setContentView(binding.getRoot());
|
||||||
final Toolbar toolbar = binding.toolbar;
|
final Toolbar toolbar = binding.toolbar;
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
createNotificationChannels();
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
setupBottomNavigationBar(true);
|
setupBottomNavigationBar(true);
|
||||||
}
|
}
|
||||||
@ -120,9 +146,11 @@ public class MainActivity extends BaseLanguageActivity {
|
|||||||
final boolean checkUpdates = settingsHelper.getBoolean(Constants.CHECK_UPDATES);
|
final boolean checkUpdates = settingsHelper.getBoolean(Constants.CHECK_UPDATES);
|
||||||
if (checkUpdates) FlavorTown.updateCheck(this);
|
if (checkUpdates) FlavorTown.updateCheck(this);
|
||||||
FlavorTown.changelogCheck(this);
|
FlavorTown.changelogCheck(this);
|
||||||
|
|
||||||
final Intent intent = getIntent();
|
final Intent intent = getIntent();
|
||||||
handleIntent(intent);
|
handleIntent(intent);
|
||||||
|
if (!TextUtils.isEmpty(cookie) && settingsHelper.getBoolean(Constants.CHECK_ACTIVITY)) {
|
||||||
|
bindActivityCheckerService();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -176,6 +204,24 @@ public class MainActivity extends BaseLanguageActivity {
|
|||||||
handleIntent(intent);
|
handleIntent(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
unbindActivityCheckerService();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createNotificationChannels() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());
|
||||||
|
notificationManager.createNotificationChannel(new NotificationChannel(Constants.DOWNLOAD_CHANNEL_ID,
|
||||||
|
Constants.DOWNLOAD_CHANNEL_NAME,
|
||||||
|
NotificationManager.IMPORTANCE_DEFAULT));
|
||||||
|
notificationManager.createNotificationChannel(new NotificationChannel(Constants.ACTIVITY_CHANNEL_ID,
|
||||||
|
Constants.ACTIVITY_CHANNEL_NAME,
|
||||||
|
NotificationManager.IMPORTANCE_DEFAULT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setupSuggestions() {
|
private void setupSuggestions() {
|
||||||
suggestionsFetchHandler = new Handler();
|
suggestionsFetchHandler = new Handler();
|
||||||
suggestionAdapter = new SuggestionsAdapter(this, (type, query) -> {
|
suggestionAdapter = new SuggestionsAdapter(this, (type, query) -> {
|
||||||
@ -318,7 +364,7 @@ public class MainActivity extends BaseLanguageActivity {
|
|||||||
private void setupBottomNavigationBar(final boolean setDefaultFromSettings) {
|
private void setupBottomNavigationBar(final boolean setDefaultFromSettings) {
|
||||||
int main_nav_ids = R.array.main_nav_ids;
|
int main_nav_ids = R.array.main_nav_ids;
|
||||||
final String cookie = settingsHelper.getString(Constants.COOKIE);
|
final String cookie = settingsHelper.getString(Constants.COOKIE);
|
||||||
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
|
final boolean isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
main_nav_ids = R.array.logged_out_main_nav_ids;
|
main_nav_ids = R.array.logged_out_main_nav_ids;
|
||||||
binding.bottomNavView.getMenu().clear();
|
binding.bottomNavView.getMenu().clear();
|
||||||
@ -429,6 +475,10 @@ public class MainActivity extends BaseLanguageActivity {
|
|||||||
final String type = intent.getType();
|
final String type = intent.getType();
|
||||||
// Log.d(TAG, action + " " + type);
|
// Log.d(TAG, action + " " + type);
|
||||||
if (Intent.ACTION_MAIN.equals(action)) return;
|
if (Intent.ACTION_MAIN.equals(action)) return;
|
||||||
|
if (Constants.ACTION_SHOW_ACTIVITY.equals(action)) {
|
||||||
|
showActivityView();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Intent.ACTION_SEND.equals(action) && type != null) {
|
if (Intent.ACTION_SEND.equals(action) && type != null) {
|
||||||
if (type.equals("text/plain")) {
|
if (type.equals("text/plain")) {
|
||||||
handleUrl(intent.getStringExtra(Intent.EXTRA_TEXT));
|
handleUrl(intent.getStringExtra(Intent.EXTRA_TEXT));
|
||||||
@ -511,4 +561,25 @@ public class MainActivity extends BaseLanguageActivity {
|
|||||||
bundle.putString("hashtag", "#" + hashtag);
|
bundle.putString("hashtag", "#" + hashtag);
|
||||||
navController.navigate(R.id.action_global_hashTagFragment, bundle);
|
navController.navigate(R.id.action_global_hashTagFragment, bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showActivityView() {
|
||||||
|
binding.bottomNavView.setSelectedItemId(R.id.more_nav_graph);
|
||||||
|
binding.bottomNavView.post(() -> {
|
||||||
|
final NavController navController = currentNavControllerLiveData.getValue();
|
||||||
|
if (currentNavControllerLiveData == null || navController == null) return;
|
||||||
|
final NavDirections navDirections = MorePreferencesFragmentDirections.actionMorePreferencesFragmentToNotificationsViewer();
|
||||||
|
navController.navigate(navDirections);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindActivityCheckerService() {
|
||||||
|
bindService(new Intent(this, ActivityCheckerService.class), serviceConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
isActivityCheckerServiceBound = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unbindActivityCheckerService() {
|
||||||
|
if (!isActivityCheckerServiceBound) return;
|
||||||
|
unbindService(serviceConnection);
|
||||||
|
isActivityCheckerServiceBound = false;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,7 +1,5 @@
|
|||||||
package awais.instagrabber.asyncs;
|
package awais.instagrabber.asyncs;
|
||||||
|
|
||||||
import android.app.NotificationChannel;
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -28,6 +26,7 @@ import androidx.core.content.FileProvider;
|
|||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
@ -35,17 +34,16 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
import awais.instagrabber.BuildConfig;
|
import awais.instagrabber.BuildConfig;
|
||||||
import awais.instagrabber.R;
|
import awais.instagrabber.R;
|
||||||
import awais.instagrabber.interfaces.FetchListener;
|
import awais.instagrabber.interfaces.FetchListener;
|
||||||
|
import awais.instagrabber.utils.Constants;
|
||||||
import awais.instagrabber.utils.Utils;
|
import awais.instagrabber.utils.Utils;
|
||||||
|
|
||||||
import static awais.instagrabber.utils.Constants.CHANNEL_ID;
|
|
||||||
import static awais.instagrabber.utils.Constants.CHANNEL_NAME;
|
|
||||||
import static awais.instagrabber.utils.Constants.NOTIF_GROUP_NAME;
|
import static awais.instagrabber.utils.Constants.NOTIF_GROUP_NAME;
|
||||||
import static awais.instagrabber.utils.Utils.isChannelCreated;
|
|
||||||
import static awais.instagrabber.utils.Utils.logCollector;
|
import static awais.instagrabber.utils.Utils.logCollector;
|
||||||
import static awais.instagrabber.utils.Utils.notificationManager;
|
|
||||||
import static awaisomereport.LogCollector.LogFile;
|
import static awaisomereport.LogCollector.LogFile;
|
||||||
|
|
||||||
public final class DownloadAsync extends AsyncTask<Void, Float, File> {
|
public final class DownloadAsync extends AsyncTask<Void, Float, File> {
|
||||||
|
private static final String TAG = "DownloadAsync";
|
||||||
|
|
||||||
private static int lastNotifId = 1;
|
private static int lastNotifId = 1;
|
||||||
private final int currentNotifId;
|
private final int currentNotifId;
|
||||||
private final AtomicReference<Context> context;
|
private final AtomicReference<Context> context;
|
||||||
@ -55,8 +53,12 @@ public final class DownloadAsync extends AsyncTask<Void, Float, File> {
|
|||||||
private final Resources resources;
|
private final Resources resources;
|
||||||
private final NotificationCompat.Builder downloadNotif;
|
private final NotificationCompat.Builder downloadNotif;
|
||||||
private String shortCode, username;
|
private String shortCode, username;
|
||||||
|
private final NotificationManagerCompat notificationManager;
|
||||||
|
|
||||||
public DownloadAsync(final Context context, final String url, final File outFile, final FetchListener<File> fetchListener) {
|
public DownloadAsync(@NonNull final Context context,
|
||||||
|
final String url,
|
||||||
|
final File outFile,
|
||||||
|
final FetchListener<File> fetchListener) {
|
||||||
this.context = new AtomicReference<>(context);
|
this.context = new AtomicReference<>(context);
|
||||||
this.resources = context.getResources();
|
this.resources = context.getResources();
|
||||||
this.url = url;
|
this.url = url;
|
||||||
@ -66,23 +68,18 @@ public final class DownloadAsync extends AsyncTask<Void, Float, File> {
|
|||||||
this.currentNotifId = ++lastNotifId;
|
this.currentNotifId = ++lastNotifId;
|
||||||
if (++lastNotifId + 1 == Integer.MAX_VALUE) lastNotifId = 1;
|
if (++lastNotifId + 1 == Integer.MAX_VALUE) lastNotifId = 1;
|
||||||
|
|
||||||
if (notificationManager == null)
|
|
||||||
notificationManager = NotificationManagerCompat.from(context.getApplicationContext());
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isChannelCreated) {
|
|
||||||
notificationManager.createNotificationChannel(new NotificationChannel(CHANNEL_ID,
|
|
||||||
CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH));
|
|
||||||
isChannelCreated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@StringRes final int titleRes = R.string.downloader_downloading_post;
|
@StringRes final int titleRes = R.string.downloader_downloading_post;
|
||||||
|
downloadNotif = new NotificationCompat.Builder(context, Constants.DOWNLOAD_CHANNEL_ID)
|
||||||
downloadNotif = new NotificationCompat.Builder(context, CHANNEL_ID).setCategory(NotificationCompat.CATEGORY_STATUS)
|
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
||||||
.setSmallIcon(R.mipmap.ic_launcher)
|
.setSmallIcon(R.mipmap.ic_launcher)
|
||||||
.setContentText(shortCode == null ? username : shortCode).setOngoing(true)
|
.setContentText(shortCode == null ? username : shortCode)
|
||||||
.setProgress(100, 0, false).setAutoCancel(false).setOnlyAlertOnce(true)
|
.setOngoing(true)
|
||||||
|
.setProgress(100, 0, false)
|
||||||
|
.setAutoCancel(false)
|
||||||
|
.setOnlyAlertOnce(true)
|
||||||
.setContentTitle(resources.getString(titleRes));
|
.setContentTitle(resources.getString(titleRes));
|
||||||
|
|
||||||
|
notificationManager = NotificationManagerCompat.from(context.getApplicationContext());
|
||||||
notificationManager.notify(currentNotifId, downloadNotif.build());
|
notificationManager.notify(currentNotifId, downloadNotif.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +155,7 @@ public final class DownloadAsync extends AsyncTask<Void, Float, File> {
|
|||||||
new Pair<>("downloadNotif", downloadNotif),
|
new Pair<>("downloadNotif", downloadNotif),
|
||||||
new Pair<>("currentNotifId", currentNotifId),
|
new Pair<>("currentNotifId", currentNotifId),
|
||||||
new Pair<>("notificationManager", notificationManager));
|
new Pair<>("notificationManager", notificationManager));
|
||||||
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
|
if (BuildConfig.DEBUG) Log.e(TAG, "", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -193,12 +190,12 @@ public final class DownloadAsync extends AsyncTask<Void, Float, File> {
|
|||||||
final ContentResolver contentResolver = context.getContentResolver();
|
final ContentResolver contentResolver = context.getContentResolver();
|
||||||
Bitmap bitmap = null;
|
Bitmap bitmap = null;
|
||||||
if (Utils.isImage(uri, contentResolver)) {
|
if (Utils.isImage(uri, contentResolver)) {
|
||||||
try {
|
try (final InputStream inputStream = contentResolver.openInputStream(uri)) {
|
||||||
bitmap = BitmapFactory.decodeStream(contentResolver.openInputStream(uri));
|
bitmap = BitmapFactory.decodeStream(inputStream);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
if (logCollector != null)
|
if (logCollector != null)
|
||||||
logCollector.appendException(e, LogFile.ASYNC_DOWNLOADER, "onPostExecute::bitmap_1");
|
logCollector.appendException(e, LogFile.ASYNC_DOWNLOADER, "onPostExecute::bitmap_1");
|
||||||
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
|
if (BuildConfig.DEBUG) Log.e(TAG, "", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,25 +9,24 @@ import java.net.HttpURLConnection;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import awais.instagrabber.utils.Constants;
|
import awais.instagrabber.utils.Constants;
|
||||||
|
import awais.instagrabber.utils.CookieUtils;
|
||||||
import awais.instagrabber.utils.NetworkUtils;
|
import awais.instagrabber.utils.NetworkUtils;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
|
|
||||||
public class GetActivityAsyncTask extends AsyncTask<Void, Void, GetActivityAsyncTask.NotificationCounts> {
|
public class GetActivityAsyncTask extends AsyncTask<String, Void, GetActivityAsyncTask.NotificationCounts> {
|
||||||
private static final String TAG = "GetActivityAsyncTask";
|
private static final String TAG = "GetActivityAsyncTask";
|
||||||
private String uid;
|
|
||||||
private String cookie;
|
|
||||||
private OnTaskCompleteListener onTaskCompleteListener;
|
private OnTaskCompleteListener onTaskCompleteListener;
|
||||||
|
|
||||||
public GetActivityAsyncTask(final String uid, final String cookie, final OnTaskCompleteListener onTaskCompleteListener) {
|
public GetActivityAsyncTask(final OnTaskCompleteListener onTaskCompleteListener) {
|
||||||
this.uid = uid;
|
|
||||||
this.cookie = cookie;
|
|
||||||
this.onTaskCompleteListener = onTaskCompleteListener;
|
this.onTaskCompleteListener = onTaskCompleteListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NotificationCounts doInBackground(Void... voids) {
|
protected NotificationCounts doInBackground(final String... cookiesArray) {
|
||||||
if (TextUtils.isEmpty(cookie)) {
|
if (cookiesArray == null) return null;
|
||||||
return null;
|
final String cookie = cookiesArray[0];
|
||||||
}
|
if (TextUtils.isEmpty(cookie)) return null;
|
||||||
|
final String uid = CookieUtils.getUserIdFromCookie(cookie);
|
||||||
final String url = "https://www.instagram.com/graphql/query/?query_hash=0f318e8cfff9cc9ef09f88479ff571fb"
|
final String url = "https://www.instagram.com/graphql/query/?query_hash=0f318e8cfff9cc9ef09f88479ff571fb"
|
||||||
+ "&variables={\"id\":\"" + uid + "\"}";
|
+ "&variables={\"id\":\"" + uid + "\"}";
|
||||||
HttpURLConnection urlConnection = null;
|
HttpURLConnection urlConnection = null;
|
||||||
@ -40,8 +39,12 @@ public class GetActivityAsyncTask extends AsyncTask<Void, Void, GetActivityAsync
|
|||||||
if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final JSONObject data = new JSONObject(NetworkUtils.readFromConnection(urlConnection)).getJSONObject("data")
|
final JSONObject data = new JSONObject(NetworkUtils.readFromConnection(urlConnection))
|
||||||
.getJSONObject("user").getJSONObject("edge_activity_count").getJSONArray("edges").getJSONObject(0)
|
.getJSONObject("data")
|
||||||
|
.getJSONObject("user")
|
||||||
|
.getJSONObject("edge_activity_count")
|
||||||
|
.getJSONArray("edges")
|
||||||
|
.getJSONObject(0)
|
||||||
.getJSONObject("node");
|
.getJSONObject("node");
|
||||||
return new NotificationCounts(
|
return new NotificationCounts(
|
||||||
data.getInt("relationships"),
|
data.getInt("relationships"),
|
||||||
@ -62,9 +65,7 @@ public class GetActivityAsyncTask extends AsyncTask<Void, Void, GetActivityAsync
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(final NotificationCounts result) {
|
protected void onPostExecute(final NotificationCounts result) {
|
||||||
if (onTaskCompleteListener == null) {
|
if (onTaskCompleteListener == null) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
onTaskCompleteListener.onTaskComplete(result);
|
onTaskCompleteListener.onTaskComplete(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,6 +107,17 @@ public class GetActivityAsyncTask extends AsyncTask<Void, Void, GetActivityAsync
|
|||||||
public int getLikesCount() {
|
public int getLikesCount() {
|
||||||
return likesCount;
|
return likesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "NotificationCounts{" +
|
||||||
|
"relationshipsCount=" + relationshipsCount +
|
||||||
|
", userTagsCount=" + userTagsCount +
|
||||||
|
", commentsCount=" + commentsCount +
|
||||||
|
", commentLikesCount=" + commentLikesCount +
|
||||||
|
", likesCount=" + likesCount +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnTaskCompleteListener {
|
public interface OnTaskCompleteListener {
|
||||||
|
@ -3,21 +3,19 @@ package awais.instagrabber.directdownload;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationChannel;
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
import androidx.core.app.NotificationManagerCompat;
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
@ -37,15 +35,17 @@ import awais.instagrabber.utils.DownloadUtils;
|
|||||||
import awais.instagrabber.utils.IntentUtils;
|
import awais.instagrabber.utils.IntentUtils;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
|
|
||||||
import static awais.instagrabber.utils.Constants.CHANNEL_ID;
|
|
||||||
import static awais.instagrabber.utils.Constants.CHANNEL_NAME;
|
|
||||||
import static awais.instagrabber.utils.Utils.isChannelCreated;
|
|
||||||
import static awais.instagrabber.utils.Utils.notificationManager;
|
|
||||||
|
|
||||||
public final class DirectDownload extends Activity {
|
public final class DirectDownload extends Activity {
|
||||||
private boolean isFound = false;
|
private boolean isFound = false;
|
||||||
private Intent intent;
|
private Intent intent;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
private NotificationManagerCompat notificationManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
notificationManager = NotificationManagerCompat.from(getApplicationContext());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWindowAttributesChanged(final WindowManager.LayoutParams params) {
|
public void onWindowAttributesChanged(final WindowManager.LayoutParams params) {
|
||||||
@ -92,7 +92,7 @@ public final class DirectDownload extends Activity {
|
|||||||
|
|
||||||
private synchronized void doDownload() {
|
private synchronized void doDownload() {
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
if (!TextUtils.isEmpty(action) && !Intent.ACTION_MAIN.equals(action)) {
|
if (TextUtils.isEmpty(action) || Intent.ACTION_MAIN.equals(action)) return;
|
||||||
boolean error = true;
|
boolean error = true;
|
||||||
|
|
||||||
String data = null;
|
String data = null;
|
||||||
@ -118,15 +118,7 @@ public final class DirectDownload extends Activity {
|
|||||||
new PostFetcher(text, new FetchListener<ViewerPostModel[]>() {
|
new PostFetcher(text, new FetchListener<ViewerPostModel[]>() {
|
||||||
@Override
|
@Override
|
||||||
public void doBefore() {
|
public void doBefore() {
|
||||||
if (notificationManager == null)
|
final Notification fetchingPostNotif = new NotificationCompat.Builder(context, Constants.DOWNLOAD_CHANNEL_ID)
|
||||||
notificationManager = NotificationManagerCompat.from(context.getApplicationContext());
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isChannelCreated) {
|
|
||||||
notificationManager.createNotificationChannel(new NotificationChannel(CHANNEL_ID,
|
|
||||||
CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH));
|
|
||||||
isChannelCreated = true;
|
|
||||||
}
|
|
||||||
final Notification fetchingPostNotif = new NotificationCompat.Builder(context, CHANNEL_ID)
|
|
||||||
.setCategory(NotificationCompat.CATEGORY_STATUS).setSmallIcon(R.mipmap.ic_launcher)
|
.setCategory(NotificationCompat.CATEGORY_STATUS).setSmallIcon(R.mipmap.ic_launcher)
|
||||||
.setAutoCancel(false).setPriority(NotificationCompat.PRIORITY_MIN)
|
.setAutoCancel(false).setPriority(NotificationCompat.PRIORITY_MIN)
|
||||||
.setContentText(context.getString(R.string.direct_download_loading)).build();
|
.setContentText(context.getString(R.string.direct_download_loading)).build();
|
||||||
@ -151,5 +143,4 @@ public final class DirectDownload extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package awais.instagrabber.fragments;
|
package awais.instagrabber.fragments;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -15,6 +16,7 @@ import android.widget.Toast;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.navigation.NavDirections;
|
import androidx.navigation.NavDirections;
|
||||||
@ -31,16 +33,14 @@ import awais.instagrabber.fragments.settings.MorePreferencesFragmentDirections;
|
|||||||
import awais.instagrabber.interfaces.MentionClickListener;
|
import awais.instagrabber.interfaces.MentionClickListener;
|
||||||
import awais.instagrabber.models.enums.NotificationType;
|
import awais.instagrabber.models.enums.NotificationType;
|
||||||
import awais.instagrabber.repositories.responses.FriendshipRepoChangeRootResponse;
|
import awais.instagrabber.repositories.responses.FriendshipRepoChangeRootResponse;
|
||||||
import awais.instagrabber.webservices.FriendshipService;
|
|
||||||
import awais.instagrabber.webservices.NewsService;
|
|
||||||
import awais.instagrabber.webservices.ServiceCallback;
|
|
||||||
import awais.instagrabber.utils.Constants;
|
import awais.instagrabber.utils.Constants;
|
||||||
import awais.instagrabber.utils.CookieUtils;
|
import awais.instagrabber.utils.CookieUtils;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
import awais.instagrabber.utils.Utils;
|
import awais.instagrabber.utils.Utils;
|
||||||
import awais.instagrabber.viewmodels.NotificationViewModel;
|
import awais.instagrabber.viewmodels.NotificationViewModel;
|
||||||
|
import awais.instagrabber.webservices.FriendshipService;
|
||||||
import static awais.instagrabber.utils.Utils.notificationManager;
|
import awais.instagrabber.webservices.NewsService;
|
||||||
|
import awais.instagrabber.webservices.ServiceCallback;
|
||||||
|
|
||||||
public final class NotificationsViewerFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
public final class NotificationsViewerFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||||
private static final String TAG = "NotificationsViewer";
|
private static final String TAG = "NotificationsViewer";
|
||||||
@ -145,10 +145,12 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
notificationManager.cancel(Constants.ACTIVITY_NOTIFICATION_ID);
|
final Context context = getContext();
|
||||||
|
if (context == null) return;
|
||||||
|
NotificationManagerCompat.from(context.getApplicationContext()).cancel(Constants.ACTIVITY_NOTIFICATION_ID);
|
||||||
final String cookie = Utils.settingsHelper.getString(Constants.COOKIE);
|
final String cookie = Utils.settingsHelper.getString(Constants.COOKIE);
|
||||||
if (TextUtils.isEmpty(cookie)) {
|
if (TextUtils.isEmpty(cookie)) {
|
||||||
Toast.makeText(getContext(), R.string.activity_notloggedin, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, R.string.activity_notloggedin, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
friendshipService = FriendshipService.getInstance();
|
friendshipService = FriendshipService.getInstance();
|
||||||
newsService = NewsService.getInstance();
|
newsService = NewsService.getInstance();
|
||||||
|
@ -79,8 +79,7 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
|
|||||||
loggedInUsersPreferenceCategory.addPreference(getMarkStoriesSeenPreference());
|
loggedInUsersPreferenceCategory.addPreference(getMarkStoriesSeenPreference());
|
||||||
loggedInUsersPreferenceCategory.addPreference(getMarkDMSeenPreference());
|
loggedInUsersPreferenceCategory.addPreference(getMarkDMSeenPreference());
|
||||||
loggedInUsersPreferenceCategory.addPreference(getEnableActivityNotificationsPreference());
|
loggedInUsersPreferenceCategory.addPreference(getEnableActivityNotificationsPreference());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
final PreferenceCategory anonUsersPreferenceCategory = new PreferenceCategory(requireContext());
|
final PreferenceCategory anonUsersPreferenceCategory = new PreferenceCategory(requireContext());
|
||||||
screen.addPreference(anonUsersPreferenceCategory);
|
screen.addPreference(anonUsersPreferenceCategory);
|
||||||
anonUsersPreferenceCategory.setIconSpaceReserved(false);
|
anonUsersPreferenceCategory.setIconSpaceReserved(false);
|
||||||
@ -242,6 +241,10 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
|
|||||||
preference.setKey(Constants.CHECK_ACTIVITY);
|
preference.setKey(Constants.CHECK_ACTIVITY);
|
||||||
preference.setTitle(R.string.activity_setting);
|
preference.setTitle(R.string.activity_setting);
|
||||||
preference.setIconSpaceReserved(false);
|
preference.setIconSpaceReserved(false);
|
||||||
|
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
|
||||||
|
shouldRecreate();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
return preference;
|
return preference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,132 @@
|
|||||||
|
package awais.instagrabber.services;
|
||||||
|
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.app.Service;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Binder;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.core.app.NotificationCompat;
|
||||||
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import awais.instagrabber.R;
|
||||||
|
import awais.instagrabber.activities.MainActivity;
|
||||||
|
import awais.instagrabber.asyncs.GetActivityAsyncTask;
|
||||||
|
import awais.instagrabber.asyncs.GetActivityAsyncTask.NotificationCounts;
|
||||||
|
import awais.instagrabber.asyncs.GetActivityAsyncTask.OnTaskCompleteListener;
|
||||||
|
import awais.instagrabber.utils.Constants;
|
||||||
|
|
||||||
|
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||||
|
|
||||||
|
public class ActivityCheckerService extends Service {
|
||||||
|
private static final String TAG = "ActivityCheckerService";
|
||||||
|
private static final int INITIAL_DELAY_MILLIS = 200;
|
||||||
|
private static final int DELAY_MILLIS = 60000;
|
||||||
|
|
||||||
|
private Handler handler;
|
||||||
|
private OnTaskCompleteListener onTaskCompleteListener;
|
||||||
|
private NotificationManagerCompat notificationManager;
|
||||||
|
|
||||||
|
private final IBinder binder = new LocalBinder();
|
||||||
|
private final Runnable runnable = () -> {
|
||||||
|
final String cookie = settingsHelper.getString(Constants.COOKIE);
|
||||||
|
final GetActivityAsyncTask activityAsyncTask = new GetActivityAsyncTask(onTaskCompleteListener);
|
||||||
|
activityAsyncTask.execute(cookie);
|
||||||
|
};
|
||||||
|
|
||||||
|
public class LocalBinder extends Binder {
|
||||||
|
public ActivityCheckerService getService() {
|
||||||
|
return ActivityCheckerService.this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
notificationManager = NotificationManagerCompat.from(getApplicationContext());
|
||||||
|
handler = new Handler();
|
||||||
|
onTaskCompleteListener = result -> {
|
||||||
|
// Log.d(TAG, "onTaskCompleteListener: result: " + result);
|
||||||
|
try {
|
||||||
|
if (result == null) return;
|
||||||
|
final String notification = getNotificationString(result);
|
||||||
|
if (notification == null) return;
|
||||||
|
final String notificationString = getString(R.string.activity_count_prefix) + " " + notification + ".";
|
||||||
|
showNotification(notificationString);
|
||||||
|
} finally {
|
||||||
|
handler.postDelayed(runnable, DELAY_MILLIS);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBinder onBind(Intent intent) {
|
||||||
|
startChecking();
|
||||||
|
// Uncomment to test notifications
|
||||||
|
// final String notificationString = getNotificationString(new NotificationCounts(
|
||||||
|
// 1,
|
||||||
|
// 2,
|
||||||
|
// 3,
|
||||||
|
// 4,
|
||||||
|
// 5
|
||||||
|
// ));
|
||||||
|
// showNotification(notificationString);
|
||||||
|
return binder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onUnbind(final Intent intent) {
|
||||||
|
stopChecking();
|
||||||
|
return super.onUnbind(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startChecking() {
|
||||||
|
handler.postDelayed(runnable, INITIAL_DELAY_MILLIS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopChecking() {
|
||||||
|
handler.removeCallbacks(runnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getNotificationString(final NotificationCounts result) {
|
||||||
|
final List<String> list = new ArrayList<>();
|
||||||
|
if (result.getRelationshipsCount() != 0) {
|
||||||
|
list.add(getString(R.string.activity_count_relationship, result.getRelationshipsCount()));
|
||||||
|
}
|
||||||
|
if (result.getUserTagsCount() != 0) {
|
||||||
|
list.add(getString(R.string.activity_count_usertags, result.getUserTagsCount()));
|
||||||
|
}
|
||||||
|
if (result.getCommentsCount() != 0) {
|
||||||
|
list.add(getString(R.string.activity_count_comments, result.getCommentsCount()));
|
||||||
|
}
|
||||||
|
if (result.getCommentLikesCount() != 0) {
|
||||||
|
list.add(getString(R.string.activity_count_commentlikes, result.getCommentLikesCount()));
|
||||||
|
}
|
||||||
|
if (result.getLikesCount() != 0) {
|
||||||
|
list.add(getString(R.string.activity_count_likes, result.getLikesCount()));
|
||||||
|
}
|
||||||
|
if (list.isEmpty()) return null;
|
||||||
|
return TextUtils.join(", ", list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showNotification(final String notificationString) {
|
||||||
|
final Intent intent = new Intent(getApplicationContext(), MainActivity.class)
|
||||||
|
.setAction(Constants.ACTION_SHOW_ACTIVITY)
|
||||||
|
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
final Notification notification = new NotificationCompat.Builder(this, Constants.ACTIVITY_CHANNEL_ID)
|
||||||
|
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
||||||
|
.setSmallIcon(R.drawable.ic_notif)
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_MIN)
|
||||||
|
.setContentTitle(getString(R.string.action_notif))
|
||||||
|
.setContentText(notificationString)
|
||||||
|
.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 1738, intent, PendingIntent.FLAG_UPDATE_CURRENT))
|
||||||
|
.build();
|
||||||
|
notificationManager.notify(Constants.ACTIVITY_NOTIFICATION_ID, notification);
|
||||||
|
}
|
||||||
|
}
|
@ -71,8 +71,11 @@ public final class Constants {
|
|||||||
public static final String FDROID_SHA1_FINGERPRINT = "C1661EB8FD09F618307E687786D5E5056F65084D";
|
public static final String FDROID_SHA1_FINGERPRINT = "C1661EB8FD09F618307E687786D5E5056F65084D";
|
||||||
public static final String SKIPPED_VERSION = "skipped_version";
|
public static final String SKIPPED_VERSION = "skipped_version";
|
||||||
public static final String DEFAULT_TAB = "default_tab";
|
public static final String DEFAULT_TAB = "default_tab";
|
||||||
public static final String CHANNEL_ID = "InstaGrabber";
|
public static final String ACTIVITY_CHANNEL_ID = "activity";
|
||||||
public static final String CHANNEL_NAME = "Instagrabber";
|
public static final String DOWNLOAD_CHANNEL_ID = "download";
|
||||||
|
public static final String ACTIVITY_CHANNEL_NAME = "Activity";
|
||||||
|
public static final String DOWNLOAD_CHANNEL_NAME = "Downloads";
|
||||||
public static final String NOTIF_GROUP_NAME = "awais.instagrabber.InstaNotif";
|
public static final String NOTIF_GROUP_NAME = "awais.instagrabber.InstaNotif";
|
||||||
public static final int ACTIVITY_NOTIFICATION_ID = 1800000000;
|
public static final int ACTIVITY_NOTIFICATION_ID = 1800000000;
|
||||||
|
public static final String ACTION_SHOW_ACTIVITY = "show_activity";
|
||||||
}
|
}
|
@ -6,8 +6,6 @@ import android.content.ClipData;
|
|||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -21,11 +19,9 @@ import android.webkit.MimeTypeMap;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
import androidx.core.app.NotificationManagerCompat;
|
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
|
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
|
||||||
@ -56,9 +52,7 @@ public final class Utils {
|
|||||||
public static SettingsHelper settingsHelper;
|
public static SettingsHelper settingsHelper;
|
||||||
public static DataBox dataBox;
|
public static DataBox dataBox;
|
||||||
public static boolean sessionVolumeFull = false;
|
public static boolean sessionVolumeFull = false;
|
||||||
public static NotificationManagerCompat notificationManager;
|
|
||||||
public static final MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
|
public static final MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
|
||||||
public static boolean isChannelCreated = false;
|
|
||||||
public static ClipboardManager clipboardManager;
|
public static ClipboardManager clipboardManager;
|
||||||
public static DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
|
public static DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
|
||||||
public static SimpleDateFormat datetimeParser;
|
public static SimpleDateFormat datetimeParser;
|
||||||
@ -122,8 +116,8 @@ public final class Utils {
|
|||||||
clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
|
||||||
int toastMessage = R.string.clipboard_error;
|
int toastMessage = R.string.clipboard_error;
|
||||||
if (clipboardManager != null) {
|
if (clipboardManager != null && ctxNotNull) {
|
||||||
clipboardManager.setPrimaryClip(ClipData.newPlainText(Constants.CHANNEL_NAME, string));
|
clipboardManager.setPrimaryClip(ClipData.newPlainText(context.getString(R.string.app_name), string));
|
||||||
toastMessage = R.string.clipboard_copied;
|
toastMessage = R.string.clipboard_copied;
|
||||||
}
|
}
|
||||||
if (ctxNotNull) Toast.makeText(context, toastMessage, Toast.LENGTH_SHORT).show();
|
if (ctxNotNull) Toast.makeText(context, toastMessage, Toast.LENGTH_SHORT).show();
|
||||||
|
Loading…
Reference in New Issue
Block a user