mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-08 16:36:10 +00:00
Feedback when restore is finished
This commit is contained in:
parent
09ab64044d
commit
b13e98e2dc
@ -65,8 +65,9 @@ public class RestoreMessagesActivity extends AppCompatActivity {
|
||||
throw new IllegalStateException(getString(R.string.err_didnt_find_account_restore));
|
||||
}
|
||||
|
||||
TextView tv = (TextView) findViewById(R.id.tv_error_default_smsapp);
|
||||
tv.setText(R.string.error_make_default_sms_app);
|
||||
TextView tv_error = (TextView) findViewById(R.id.tv_error_default_smsapp);
|
||||
tv_error.setText(R.string.error_make_default_sms_app);
|
||||
findViewById(R.id.tv_restore_finished).setVisibility(View.INVISIBLE);
|
||||
Button fix_button = (Button) findViewById(R.id.button_fix_permissions);
|
||||
final Button launch_restore = (Button) findViewById(R.id.button_launch_restore);
|
||||
final ProgressBar pb = (ProgressBar) findViewById(R.id.progressbar_restore);
|
||||
@ -80,12 +81,12 @@ public class RestoreMessagesActivity extends AppCompatActivity {
|
||||
_defaultSmsApp = Telephony.Sms.getDefaultSmsPackage(this);
|
||||
if (!Telephony.Sms.getDefaultSmsPackage(this).equals(getPackageName())) {
|
||||
_defaultSmsApp = Telephony.Sms.getDefaultSmsPackage(getBaseContext());
|
||||
tv.setVisibility(View.VISIBLE);
|
||||
tv_error.setVisibility(View.VISIBLE);
|
||||
fix_button.setVisibility(View.VISIBLE);
|
||||
launch_restore.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
else {
|
||||
tv.setVisibility(View.INVISIBLE);
|
||||
tv_error.setVisibility(View.INVISIBLE);
|
||||
fix_button.setVisibility(View.INVISIBLE);
|
||||
launch_restore.setVisibility(View.VISIBLE);
|
||||
}
|
||||
@ -105,12 +106,15 @@ public class RestoreMessagesActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
final RestoreMessagesActivity me = this;
|
||||
launch_restore.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
launch_restore.setVisibility(View.INVISIBLE);
|
||||
pb.setVisibility(View.VISIBLE);
|
||||
|
||||
// Verify connectivity
|
||||
Log.i(RestoreMessagesActivity.TAG, "Launching restore asynchronously");
|
||||
new ASyncSMSRecovery.SMSRecoveryTask(getApplicationContext(), _account).execute();
|
||||
new ASyncSMSRecovery.SMSRecoveryTask(me, _account).execute();
|
||||
}
|
||||
});
|
||||
|
||||
@ -149,5 +153,12 @@ public class RestoreMessagesActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
public void onRestoreDone() {
|
||||
// @TODO
|
||||
Log.i(RestoreMessagesActivity.TAG, "Sync is done, updating interface");
|
||||
findViewById(R.id.progressbar_restore).setVisibility(View.INVISIBLE);
|
||||
findViewById(R.id.tv_restore_finished).setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private static final String TAG = RestoreMessagesActivity.class.getSimpleName();
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ package fr.unix_experience.owncloud_sms.engine;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.provider.Telephony;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
@ -12,6 +12,7 @@ import org.json.JSONObject;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import fr.unix_experience.owncloud_sms.activities.remote_account.RestoreMessagesActivity;
|
||||
import fr.unix_experience.owncloud_sms.enums.MailboxID;
|
||||
|
||||
/*
|
||||
@ -33,10 +34,10 @@ import fr.unix_experience.owncloud_sms.enums.MailboxID;
|
||||
|
||||
public interface ASyncSMSRecovery {
|
||||
class SMSRecoveryTask extends AsyncTask<Void, Void, Void> {
|
||||
private final Context _context;
|
||||
private final RestoreMessagesActivity _context;
|
||||
private final Account _account;
|
||||
|
||||
public SMSRecoveryTask(Context context, Account account) {
|
||||
public SMSRecoveryTask(RestoreMessagesActivity context, Account account) {
|
||||
_context = context;
|
||||
_account = account;
|
||||
}
|
||||
@ -65,9 +66,12 @@ public interface ASyncSMSRecovery {
|
||||
if (messages.get(key) instanceof JSONObject) {
|
||||
JSONObject msg = messages.getJSONObject(key);
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("address", msg.getString("address"));
|
||||
values.put("body", msg.getString("msg"));
|
||||
values.put("date", Long.parseLong(key));
|
||||
values.put(Telephony.Sms.ADDRESS, msg.getString("address"));
|
||||
values.put(Telephony.Sms.BODY, msg.getString("msg"));
|
||||
values.put(Telephony.Sms.DATE, key);
|
||||
values.put(Telephony.Sms.DATE_SENT, key);
|
||||
values.put(Telephony.Sms.TYPE, msg.getInt("type"));
|
||||
values.put(Telephony.Sms.SEEN, 1);
|
||||
|
||||
MailboxID mailbox_id = MailboxID.fromInt(msg.getInt("mailbox"));
|
||||
_context.getContentResolver().insert(Uri.parse(mailbox_id.getURI()), values);
|
||||
@ -75,7 +79,6 @@ public interface ASyncSMSRecovery {
|
||||
}
|
||||
|
||||
while (obj.getLong("last_id") != start) {
|
||||
Log.i(TAG, obj.toString());
|
||||
start = obj.getLong("last_id");
|
||||
obj = new OCSMSOwnCloudClient(_context, _account).retrieveSomeMessages(start, 500);
|
||||
}
|
||||
@ -85,6 +88,12 @@ public interface ASyncSMSRecovery {
|
||||
Log.i(ASyncSMSRecovery.TAG, "Finishing background recovery");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
_context.onRestoreDone();
|
||||
}
|
||||
}
|
||||
|
||||
String TAG = ASyncSMSRecovery.class.getSimpleName();
|
||||
|
@ -82,4 +82,17 @@
|
||||
android:layout_alignBottom="@+id/button_fix_permissions"
|
||||
android:layout_centerHorizontal="true"/>
|
||||
|
||||
<TextView
|
||||
android:text="@string/restore_finished"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:id="@+id/tv_restore_finished"
|
||||
android:textSize="24sp"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/holo_green_dark"
|
||||
android:textAllCaps="false"
|
||||
android:visibility="invisible"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
@ -251,4 +251,5 @@
|
||||
<string name="error_make_default_sms_app">Please make this application default SMS application to permit restore your messages. This limitation has been introduced by Android 4.4.</string>
|
||||
<string name="fix_permissions">Fix permissions</string>
|
||||
<string name="err_kitkat_required">Android 4.4 or greater is required to use this feature.</string>
|
||||
<string name="restore_finished">SMS restauration is now finished.</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user