mirror of
				https://github.com/KokaKiwi/BarInsta
				synced 2025-10-31 19:45:35 +00:00 
			
		
		
		
	Start sync service after boot complete and update default freq to 30 secs.
This commit is contained in:
		
							parent
							
								
									a6d8de87ea
								
							
						
					
					
						commit
						1bd7f9add4
					
				| @ -8,6 +8,7 @@ | |||||||
|     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> |     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||||||
|     <uses-permission android:name="android.permission.RECORD_AUDIO" /> |     <uses-permission android:name="android.permission.RECORD_AUDIO" /> | ||||||
|     <uses-permission android:name="android.permission.CAMERA" /> |     <uses-permission android:name="android.permission.CAMERA" /> | ||||||
|  |     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> | ||||||
| 
 | 
 | ||||||
|     <uses-feature |     <uses-feature | ||||||
|         android:name="android.hardware.camera.any" |         android:name="android.hardware.camera.any" | ||||||
| @ -154,6 +155,11 @@ | |||||||
|             android:name=".services.DMSyncAlarmReceiver" |             android:name=".services.DMSyncAlarmReceiver" | ||||||
|             android:enabled="true" |             android:enabled="true" | ||||||
|             android:exported="false" /> |             android:exported="false" /> | ||||||
|  |         <receiver android:name=".services.BootCompletedReceiver" > | ||||||
|  |             <intent-filter> | ||||||
|  |                 <action android:name="android.intent.action.BOOT_COMPLETED" /> | ||||||
|  |             </intent-filter> | ||||||
|  |         </receiver> | ||||||
| 
 | 
 | ||||||
|         <uses-library |         <uses-library | ||||||
|             android:name="org.apache.http.legacy" |             android:name="org.apache.http.legacy" | ||||||
|  | |||||||
| @ -174,7 +174,7 @@ public class DMPreferencesFragment extends BasePreferencesFragment { | |||||||
|         private void setupNumberEditText(final Context context) { |         private void setupNumberEditText(final Context context) { | ||||||
|             int currentValue = settingsHelper.getInteger(PREF_ENABLE_DM_AUTO_REFRESH_FREQ_NUMBER); |             int currentValue = settingsHelper.getInteger(PREF_ENABLE_DM_AUTO_REFRESH_FREQ_NUMBER); | ||||||
|             if (currentValue <= 0) { |             if (currentValue <= 0) { | ||||||
|                 currentValue = 5; |                 currentValue = 30; | ||||||
|             } |             } | ||||||
|             binding.freqNum.setText(String.valueOf(currentValue)); |             binding.freqNum.setText(String.valueOf(currentValue)); | ||||||
|             binding.freqNum.addTextChangedListener(new TextWatcherAdapter() { |             binding.freqNum.addTextChangedListener(new TextWatcherAdapter() { | ||||||
|  | |||||||
| @ -0,0 +1,27 @@ | |||||||
|  | package awais.instagrabber.services; | ||||||
|  | 
 | ||||||
|  | import android.content.BroadcastReceiver; | ||||||
|  | import android.content.Context; | ||||||
|  | import android.content.Intent; | ||||||
|  | 
 | ||||||
|  | import java.util.Objects; | ||||||
|  | 
 | ||||||
|  | import awais.instagrabber.fragments.settings.PreferenceKeys; | ||||||
|  | import awais.instagrabber.utils.Constants; | ||||||
|  | import awais.instagrabber.utils.CookieUtils; | ||||||
|  | import awais.instagrabber.utils.TextUtils; | ||||||
|  | 
 | ||||||
|  | import static awais.instagrabber.utils.Utils.settingsHelper; | ||||||
|  | 
 | ||||||
|  | public class BootCompletedReceiver extends BroadcastReceiver { | ||||||
|  |     @Override | ||||||
|  |     public void onReceive(final Context context, final Intent intent) { | ||||||
|  |         if (!Objects.equals(intent.getAction(), "android.intent.action.BOOT_COMPLETED")) return; | ||||||
|  |         final boolean enabled = settingsHelper.getBoolean(PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH); | ||||||
|  |         if (!enabled) return; | ||||||
|  |         final String cookie = settingsHelper.getString(Constants.COOKIE); | ||||||
|  |         final boolean isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != 0; | ||||||
|  |         if (!isLoggedIn) return; | ||||||
|  |         DMSyncAlarmReceiver.setAlarm(context); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -70,7 +70,7 @@ public class DMSyncAlarmReceiver extends BroadcastReceiver { | |||||||
|     private static long getIntervalMillis() { |     private static long getIntervalMillis() { | ||||||
|         int amount = settingsHelper.getInteger(PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH_FREQ_NUMBER); |         int amount = settingsHelper.getInteger(PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH_FREQ_NUMBER); | ||||||
|         if (amount <= 0) { |         if (amount <= 0) { | ||||||
|             amount = 5; |             amount = 30; | ||||||
|         } |         } | ||||||
|         final String unit = settingsHelper.getString(PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH_FREQ_UNIT); |         final String unit = settingsHelper.getString(PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH_FREQ_UNIT); | ||||||
|         final TemporalUnit temporalUnit; |         final TemporalUnit temporalUnit; | ||||||
|  | |||||||
| @ -40,9 +40,12 @@ import awais.instagrabber.repositories.responses.directmessages.DirectItem; | |||||||
| import awais.instagrabber.repositories.responses.directmessages.DirectThread; | import awais.instagrabber.repositories.responses.directmessages.DirectThread; | ||||||
| import awais.instagrabber.repositories.responses.directmessages.DirectThreadLastSeenAt; | import awais.instagrabber.repositories.responses.directmessages.DirectThreadLastSeenAt; | ||||||
| import awais.instagrabber.utils.Constants; | import awais.instagrabber.utils.Constants; | ||||||
|  | import awais.instagrabber.utils.CookieUtils; | ||||||
| import awais.instagrabber.utils.DMUtils; | import awais.instagrabber.utils.DMUtils; | ||||||
| import awais.instagrabber.utils.DateUtils; | import awais.instagrabber.utils.DateUtils; | ||||||
| import awais.instagrabber.utils.Utils; | import awais.instagrabber.utils.TextUtils; | ||||||
|  | 
 | ||||||
|  | import static awais.instagrabber.utils.Utils.settingsHelper; | ||||||
| 
 | 
 | ||||||
| public class DMSyncService extends LifecycleService { | public class DMSyncService extends LifecycleService { | ||||||
|     private static final String TAG = DMSyncService.class.getSimpleName(); |     private static final String TAG = DMSyncService.class.getSimpleName(); | ||||||
| @ -209,7 +212,15 @@ public class DMSyncService extends LifecycleService { | |||||||
|     @Override |     @Override | ||||||
|     public int onStartCommand(final Intent intent, final int flags, final int startId) { |     public int onStartCommand(final Intent intent, final int flags, final int startId) { | ||||||
|         super.onStartCommand(intent, flags, startId); |         super.onStartCommand(intent, flags, startId); | ||||||
|         final boolean notificationsEnabled = Utils.settingsHelper.getBoolean(PreferenceKeys.PREF_ENABLE_DM_NOTIFICATIONS); |         final String cookie = settingsHelper.getString(Constants.COOKIE); | ||||||
|  |         final boolean isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != 0; | ||||||
|  |         if (!isLoggedIn) { | ||||||
|  |             stopSelf(); | ||||||
|  |             return START_NOT_STICKY; | ||||||
|  |         } | ||||||
|  |         // Need to setup here if service was started by the boot completed receiver | ||||||
|  |         CookieUtils.setupCookies(cookie); | ||||||
|  |         final boolean notificationsEnabled = settingsHelper.getBoolean(PreferenceKeys.PREF_ENABLE_DM_NOTIFICATIONS); | ||||||
|         inboxManager.getInbox().observe(this, inboxResource -> { |         inboxManager.getInbox().observe(this, inboxResource -> { | ||||||
|             if (!notificationsEnabled || inboxResource == null || inboxResource.status != Resource.Status.SUCCESS) { |             if (!notificationsEnabled || inboxResource == null || inboxResource.status != Resource.Status.SUCCESS) { | ||||||
|                 stopSelf(); |                 stopSelf(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user