mirror of
				https://github.com/nerzhul/ownCloud-SMS-App.git
				synced 2025-10-30 18:07:51 +00:00 
			
		
		
		
	Add a label for progression, show it to user and fix sms restauration.
This is almost finished but needs some polish
This commit is contained in:
		
							parent
							
								
									13ad6237fe
								
							
						
					
					
						commit
						9bb0a7d2f2
					
				| @ -2,7 +2,7 @@ | |||||||
| <manifest package="fr.unix_experience.owncloud_sms" | <manifest package="fr.unix_experience.owncloud_sms" | ||||||
|           xmlns:android="http://schemas.android.com/apk/res/android" |           xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|           android:versionCode="41" |           android:versionCode="41" | ||||||
|           android:versionName="0.22.2"> <!-- From Android 4.0 to 7.0 --> |           android:versionName="0.22.2"> <!-- From Android 4.1 to 7.0 --> | ||||||
|     <uses-sdk android:maxSdkVersion="25"/> |     <uses-sdk android:maxSdkVersion="25"/> | ||||||
| 
 | 
 | ||||||
|     <uses-permission android:name="android.permission.READ_SMS"/> |     <uses-permission android:name="android.permission.READ_SMS"/> | ||||||
|  | |||||||
| @ -68,6 +68,7 @@ public class RestoreMessagesActivity extends AppCompatActivity { | |||||||
| 		TextView tv_error = (TextView) findViewById(R.id.tv_error_default_smsapp); | 		TextView tv_error = (TextView) findViewById(R.id.tv_error_default_smsapp); | ||||||
| 		tv_error.setText(R.string.error_make_default_sms_app); | 		tv_error.setText(R.string.error_make_default_sms_app); | ||||||
| 		findViewById(R.id.tv_restore_finished).setVisibility(View.INVISIBLE); | 		findViewById(R.id.tv_restore_finished).setVisibility(View.INVISIBLE); | ||||||
|  | 		findViewById(R.id.tv_progress_value).setVisibility(View.INVISIBLE); | ||||||
| 		Button fix_button = (Button) findViewById(R.id.button_fix_permissions); | 		Button fix_button = (Button) findViewById(R.id.button_fix_permissions); | ||||||
| 		final Button launch_restore = (Button) findViewById(R.id.button_launch_restore); | 		final Button launch_restore = (Button) findViewById(R.id.button_launch_restore); | ||||||
| 		final ProgressBar pb = (ProgressBar) findViewById(R.id.progressbar_restore); | 		final ProgressBar pb = (ProgressBar) findViewById(R.id.progressbar_restore); | ||||||
| @ -159,5 +160,14 @@ public class RestoreMessagesActivity extends AppCompatActivity { | |||||||
| 		startActivity(finalIntent); | 		startActivity(finalIntent); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	public void onProgressUpdate(Integer value) { | ||||||
|  | 		TextView tv_progress = (TextView) findViewById(R.id.tv_progress_value); | ||||||
|  | 		if (tv_progress.getVisibility() == View.INVISIBLE) { | ||||||
|  | 			tv_progress.setVisibility(View.VISIBLE); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		tv_progress.setText(value.toString() + " " + getString(R.string.x_messages_restored)); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	private static final String TAG = RestoreMessagesActivity.class.getSimpleName(); | 	private static final String TAG = RestoreMessagesActivity.class.getSimpleName(); | ||||||
| } | } | ||||||
|  | |||||||
| @ -14,6 +14,7 @@ import java.util.Iterator; | |||||||
| 
 | 
 | ||||||
| import fr.unix_experience.owncloud_sms.activities.remote_account.RestoreMessagesActivity; | import fr.unix_experience.owncloud_sms.activities.remote_account.RestoreMessagesActivity; | ||||||
| import fr.unix_experience.owncloud_sms.enums.MailboxID; | import fr.unix_experience.owncloud_sms.enums.MailboxID; | ||||||
|  | import fr.unix_experience.owncloud_sms.providers.SmsDataProvider; | ||||||
| 
 | 
 | ||||||
| /* | /* | ||||||
|  *  Copyright (c) 2014-2016, Loic Blot <loic.blot@unix-experience.fr> |  *  Copyright (c) 2014-2016, Loic Blot <loic.blot@unix-experience.fr> | ||||||
| @ -33,7 +34,7 @@ import fr.unix_experience.owncloud_sms.enums.MailboxID; | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| public interface ASyncSMSRecovery { | public interface ASyncSMSRecovery { | ||||||
| 	class SMSRecoveryTask extends AsyncTask<Void, Void, Void> { | 	class SMSRecoveryTask extends AsyncTask<Void, Integer, Void> { | ||||||
| 		private final RestoreMessagesActivity _context; | 		private final RestoreMessagesActivity _context; | ||||||
| 		private final Account _account; | 		private final Account _account; | ||||||
| 
 | 
 | ||||||
| @ -53,34 +54,54 @@ public interface ASyncSMSRecovery { | |||||||
| 			// Verify connectivity | 			// Verify connectivity | ||||||
| 
 | 
 | ||||||
| 			Long start = (long) 0; | 			Long start = (long) 0; | ||||||
| 			JSONObject obj = new OCSMSOwnCloudClient(_context, _account).retrieveSomeMessages(start, 500); | 
 | ||||||
|  | 			OCSMSOwnCloudClient client = new OCSMSOwnCloudClient(_context, _account); | ||||||
|  | 			SmsDataProvider smsDataProvider = new SmsDataProvider(_context); | ||||||
|  | 			JSONObject obj = client.retrieveSomeMessages(start, 500); | ||||||
| 			if (obj == null) { | 			if (obj == null) { | ||||||
| 				Log.i(ASyncSMSRecovery.TAG, "Retrieved returns failure"); | 				Log.i(ASyncSMSRecovery.TAG, "Retrieved returns failure"); | ||||||
| 				return null; | 				return null; | ||||||
| 			} | 			} | ||||||
|  | 
 | ||||||
|  | 			Integer nb = 0; | ||||||
| 			try { | 			try { | ||||||
|  | 				while (obj.getLong("last_id") != start) { | ||||||
| 					JSONObject messages = obj.getJSONObject("messages"); | 					JSONObject messages = obj.getJSONObject("messages"); | ||||||
| 					Iterator<?> keys = messages.keys(); | 					Iterator<?> keys = messages.keys(); | ||||||
| 					while(keys.hasNext()) { | 					while(keys.hasNext()) { | ||||||
| 						String key = (String)keys.next(); | 						String key = (String)keys.next(); | ||||||
| 						if (messages.get(key) instanceof JSONObject) { | 						if (messages.get(key) instanceof JSONObject) { | ||||||
| 							JSONObject msg = messages.getJSONObject(key); | 							JSONObject msg = messages.getJSONObject(key); | ||||||
|  | 
 | ||||||
|  | 							int mbid = msg.getInt("mailbox"); | ||||||
|  | 							// Ignore invalid mailbox | ||||||
|  | 							if (mbid > MailboxID.ALL.getId()) { | ||||||
|  | 								continue; | ||||||
|  | 							} | ||||||
|  | 
 | ||||||
|  | 							String address = msg.getString("address"); | ||||||
|  | 
 | ||||||
| 							ContentValues values = new ContentValues(); | 							ContentValues values = new ContentValues(); | ||||||
| 						values.put(Telephony.Sms.ADDRESS, msg.getString("address")); | 							values.put(Telephony.Sms.ADDRESS, address); | ||||||
| 							values.put(Telephony.Sms.BODY, msg.getString("msg")); | 							values.put(Telephony.Sms.BODY, msg.getString("msg")); | ||||||
| 							values.put(Telephony.Sms.DATE, key); | 							values.put(Telephony.Sms.DATE, key); | ||||||
| 							values.put(Telephony.Sms.TYPE, msg.getInt("type")); | 							values.put(Telephony.Sms.TYPE, msg.getInt("type")); | ||||||
| 							values.put(Telephony.Sms.SEEN, 1); | 							values.put(Telephony.Sms.SEEN, 1); | ||||||
|  | 							values.put(Telephony.Sms.READ, 1); | ||||||
| 
 | 
 | ||||||
| 						MailboxID mailbox_id = MailboxID.fromInt(msg.getInt("mailbox")); | 							MailboxID mailbox_id = MailboxID.fromInt(mbid); | ||||||
| 							// @TODO verify message exists before inserting it | 							// @TODO verify message exists before inserting it | ||||||
| 							_context.getContentResolver().insert(Uri.parse(mailbox_id.getURI()), values); | 							_context.getContentResolver().insert(Uri.parse(mailbox_id.getURI()), values); | ||||||
|  | 
 | ||||||
|  | 							nb++; | ||||||
|  | 							if ((nb % 100) == 0) { | ||||||
|  | 								publishProgress(nb); | ||||||
|  | 							} | ||||||
| 						} | 						} | ||||||
| 					} | 					} | ||||||
| 
 | 
 | ||||||
| 				while (obj.getLong("last_id") != start) { |  | ||||||
| 					start = obj.getLong("last_id"); | 					start = obj.getLong("last_id"); | ||||||
| 					obj = new OCSMSOwnCloudClient(_context, _account).retrieveSomeMessages(start, 500); | 					obj = client.retrieveSomeMessages(start, 500); | ||||||
| 				} | 				} | ||||||
| 			} catch (JSONException e) { | 			} catch (JSONException e) { | ||||||
| 				Log.e(ASyncSMSRecovery.TAG, "Missing last_id field!"); | 				Log.e(ASyncSMSRecovery.TAG, "Missing last_id field!"); | ||||||
| @ -88,15 +109,17 @@ public interface ASyncSMSRecovery { | |||||||
| 
 | 
 | ||||||
| 			// Force this refresh to fix dates | 			// Force this refresh to fix dates | ||||||
| 			_context.getContentResolver().delete(Uri.parse("content://sms/conversations/-1"), null, null); | 			_context.getContentResolver().delete(Uri.parse("content://sms/conversations/-1"), null, null); | ||||||
|  | 
 | ||||||
|  | 			publishProgress(nb); | ||||||
|  | 
 | ||||||
| 			Log.i(ASyncSMSRecovery.TAG, "Finishing background recovery"); | 			Log.i(ASyncSMSRecovery.TAG, "Finishing background recovery"); | ||||||
| 			return null; | 			return null; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		@Override | 		@Override | ||||||
| 		protected void onProgressUpdate(Void... values) { | 		protected void onProgressUpdate(Integer... values) { | ||||||
| 			super.onProgressUpdate(values); | 			super.onProgressUpdate(values); | ||||||
| 
 | 			_context.onProgressUpdate(values[0]); | ||||||
| 			// @TODO feedback user |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		@Override | 		@Override | ||||||
|  | |||||||
| @ -95,4 +95,12 @@ | |||||||
|         android:textAllCaps="false" |         android:textAllCaps="false" | ||||||
|         android:visibility="invisible"/> |         android:visibility="invisible"/> | ||||||
| 
 | 
 | ||||||
|  |     <TextView | ||||||
|  |         android:layout_width="wrap_content" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:layout_below="@+id/progressbar_restore" | ||||||
|  |         android:layout_centerHorizontal="true" | ||||||
|  |         android:id="@+id/tv_progress_value" | ||||||
|  |         android:text="@string/x_messages_restored"/> | ||||||
|  | 
 | ||||||
| </RelativeLayout> | </RelativeLayout> | ||||||
|  | |||||||
| @ -177,5 +177,6 @@ | |||||||
|     <string name="err_didnt_find_account_restore">We didn\'t find your account to restore your message, this is a very strange situation.</string> |     <string name="err_didnt_find_account_restore">We didn\'t find your account to restore your message, this is a very strange situation.</string> | ||||||
|     <string name="err_kitkat_required">Android 4.4 or greater is required to use this feature.</string> |     <string name="err_kitkat_required">Android 4.4 or greater is required to use this feature.</string> | ||||||
|     <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="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="x_messages_restored">messages restored...</string> | ||||||
| 
 | 
 | ||||||
| </resources> | </resources> | ||||||
|  | |||||||
| @ -165,4 +165,5 @@ | |||||||
|     <string name="err_kitkat_required">Android 4.4 ou plus est requis pour utiliser cette fonctionnalité.</string> |     <string name="err_kitkat_required">Android 4.4 ou plus est requis pour utiliser cette fonctionnalité.</string> | ||||||
|     <string name="err_sync_get_smslist">Erreur #1: Données invalides reçues lors de l\'obtention des messages précédents.</string> |     <string name="err_sync_get_smslist">Erreur #1: Données invalides reçues lors de l\'obtention des messages précédents.</string> | ||||||
|     <string name="error_make_default_sms_app">Merci de bien vouloir mettre cette application en application SMS par défaut le temps de restaurer les messages. Cette limitation a été ajoutée depuis Android 4.4.</string> |     <string name="error_make_default_sms_app">Merci de bien vouloir mettre cette application en application SMS par défaut le temps de restaurer les messages. Cette limitation a été ajoutée depuis Android 4.4.</string> | ||||||
|  |     <string name="x_messages_restored">messages restaurés...</string> | ||||||
| </resources> | </resources> | ||||||
|  | |||||||
| @ -252,4 +252,5 @@ | |||||||
|     <string name="fix_permissions">Fix permissions</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="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> |     <string name="restore_finished">SMS restauration is now finished.</string> | ||||||
|  |     <string name="x_messages_restored">messages restored...</string> | ||||||
| </resources> | </resources> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user