Allow to auto backup notifications #274
This commit is contained in:
parent
cd2deba3f4
commit
c6c943236c
|
@ -311,6 +311,19 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
boolean auto_backup_notifications = sharedpreferences.getBoolean(Helper.SET_AUTO_BACKUP_NOTIFICATIONS+userId+instance, false);
|
||||||
|
final CheckBox set_auto_backup_notifications = rootView.findViewById(R.id.set_auto_backup_notifications);
|
||||||
|
set_auto_backup_notifications.setChecked(auto_backup_notifications);
|
||||||
|
set_auto_backup_notifications.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
editor.putBoolean(Helper.SET_AUTO_BACKUP_NOTIFICATIONS+userId+instance, set_auto_backup_notifications.isChecked());
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
final LinearLayout set_auto_backup_text = rootView.findViewById(R.id.set_auto_backup_text);
|
final LinearLayout set_auto_backup_text = rootView.findViewById(R.id.set_auto_backup_text);
|
||||||
set_auto_backup_text.setOnClickListener(view -> set_auto_backup.performClick());
|
set_auto_backup_text.setOnClickListener(view -> set_auto_backup.performClick());
|
||||||
|
|
||||||
|
|
|
@ -372,6 +372,7 @@ public class Helper {
|
||||||
public static final String SET_DISPLAY_ADMIN_STATUSES = "set_display_admin_statuses";
|
public static final String SET_DISPLAY_ADMIN_STATUSES = "set_display_admin_statuses";
|
||||||
public static final String SET_DISPLAY_FEDILAB_FEATURES_BUTTON = "set_display_fedilab_features_button";
|
public static final String SET_DISPLAY_FEDILAB_FEATURES_BUTTON = "set_display_fedilab_features_button";
|
||||||
public static final String SET_AUTO_BACKUP_STATUSES = "set_auto_backup_statuses";
|
public static final String SET_AUTO_BACKUP_STATUSES = "set_auto_backup_statuses";
|
||||||
|
public static final String SET_AUTO_BACKUP_NOTIFICATIONS = "set_auto_backup_notifications";
|
||||||
|
|
||||||
public static final int S_NO = 0;
|
public static final int S_NO = 0;
|
||||||
static final int S_512KO = 1;
|
static final int S_512KO = 1;
|
||||||
|
|
|
@ -36,6 +36,8 @@ public class ApplicationJob implements JobCreator {
|
||||||
return new ScheduledBoostsSyncJob();
|
return new ScheduledBoostsSyncJob();
|
||||||
case BackupStatusesSyncJob.BACKUP_SYNC:
|
case BackupStatusesSyncJob.BACKUP_SYNC:
|
||||||
return new BackupStatusesSyncJob();
|
return new BackupStatusesSyncJob();
|
||||||
|
case BackupNotificationsSyncJob.BACKUP_NOTIFICATIONS_SYNC:
|
||||||
|
return new BackupNotificationsSyncJob();
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
package app.fedilab.android.jobs;
|
||||||
|
/* Copyright 2019 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Fedilab
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.evernote.android.job.Job;
|
||||||
|
import com.evernote.android.job.JobManager;
|
||||||
|
import com.evernote.android.job.JobRequest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import app.fedilab.android.client.Entities.Account;
|
||||||
|
import app.fedilab.android.helper.Helper;
|
||||||
|
import app.fedilab.android.services.BackupNotificationInDataBaseService;
|
||||||
|
import app.fedilab.android.sqlite.AccountDAO;
|
||||||
|
import app.fedilab.android.sqlite.Sqlite;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 24/08/2019.
|
||||||
|
* backup notifications
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class BackupNotificationsSyncJob extends Job {
|
||||||
|
|
||||||
|
static final String BACKUP_NOTIFICATIONS_SYNC = "job_backup_notification";
|
||||||
|
static {
|
||||||
|
Helper.installProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
protected Result onRunJob(@NonNull Params params) {
|
||||||
|
//Code refresh here
|
||||||
|
|
||||||
|
backupService();
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int schedule(boolean updateCurrent) {
|
||||||
|
|
||||||
|
Set<JobRequest> jobRequests = JobManager.instance().getAllJobRequestsForTag(BACKUP_NOTIFICATIONS_SYNC);
|
||||||
|
if (!jobRequests.isEmpty() && !updateCurrent) {
|
||||||
|
return jobRequests.iterator().next().getJobId();
|
||||||
|
}
|
||||||
|
|
||||||
|
int jobRequestschedule = -1;
|
||||||
|
try {
|
||||||
|
jobRequestschedule = new JobRequest.Builder(BackupNotificationsSyncJob.BACKUP_NOTIFICATIONS_SYNC)
|
||||||
|
.setPeriodic(TimeUnit.MINUTES.toMillis(Helper.MINUTES_BETWEEN_BACKUP), TimeUnit.MINUTES.toMillis(5))
|
||||||
|
.setUpdateCurrent(updateCurrent)
|
||||||
|
.setRequiredNetworkType(JobRequest.NetworkType.METERED)
|
||||||
|
.setRequirementsEnforced(false)
|
||||||
|
.build()
|
||||||
|
.schedule();
|
||||||
|
}catch (Exception ignored){}
|
||||||
|
|
||||||
|
return jobRequestschedule;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Task in background starts here.
|
||||||
|
*/
|
||||||
|
private void backupService() {
|
||||||
|
SQLiteDatabase db = Sqlite.getInstance(getContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
final List<Account> accounts = new AccountDAO(getContext(), db).getAllAccount();
|
||||||
|
SharedPreferences sharedpreferences = getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
for(Account account: accounts) {
|
||||||
|
boolean autobackup = sharedpreferences.getBoolean(Helper.SET_AUTO_BACKUP_NOTIFICATIONS + account.getId() + account.getInstance(), false);
|
||||||
|
if( autobackup) {
|
||||||
|
try {
|
||||||
|
Intent backupIntent = new Intent(getContext(), BackupNotificationInDataBaseService.class);
|
||||||
|
backupIntent.putExtra("userid", account.getId());
|
||||||
|
backupIntent.putExtra("instance", account.getInstance());
|
||||||
|
getContext().startService(backupIntent);
|
||||||
|
}catch (Exception ignored){}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -981,7 +981,35 @@
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/settings_checkbox_margin"
|
||||||
|
android:layout_marginBottom="@dimen/settings_checkbox_margin"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/set_auto_backup_notifications"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/set_auto_backup_text_notifications"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
<TextView
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:text="@string/set_auto_backup_notifications"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
<TextView
|
||||||
|
android:textColor="@color/mastodonC2"
|
||||||
|
android:text="@string/set_auto_backup_notifications_indication"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
<TextView
|
<TextView
|
||||||
android:text="@string/set_crash_reports"
|
android:text="@string/set_crash_reports"
|
||||||
android:layout_marginTop="@dimen/settings_checkbox_margin"
|
android:layout_marginTop="@dimen/settings_checkbox_margin"
|
||||||
|
|
|
@ -1149,6 +1149,8 @@
|
||||||
<string name="set_backup">Backup</string>
|
<string name="set_backup">Backup</string>
|
||||||
<string name="set_auto_backup">Auto backup statuses</string>
|
<string name="set_auto_backup">Auto backup statuses</string>
|
||||||
<string name="set_auto_backup_indication">This option is per account. It will launch a service that will automatically store your statuses locally in the database. That allows to get statistics and charts</string>
|
<string name="set_auto_backup_indication">This option is per account. It will launch a service that will automatically store your statuses locally in the database. That allows to get statistics and charts</string>
|
||||||
|
<string name="set_auto_backup_notifications">Auto backup notifications</string>
|
||||||
|
<string name="set_auto_backup_notifications_indication">This option is per account. It will launch a service that will automatically store your notifications locally in the database. That allows to get statistics and charts</string>
|
||||||
<string name="report_account">Report account</string>
|
<string name="report_account">Report account</string>
|
||||||
<string name="send_invitation">Send an invitation</string>
|
<string name="send_invitation">Send an invitation</string>
|
||||||
<string name="registration_closed">Your instance does not allow to register a new account!</string>
|
<string name="registration_closed">Your instance does not allow to register a new account!</string>
|
||||||
|
|
Loading…
Reference in New Issue