mirror of
				https://github.com/nerzhul/ownCloud-SMS-App.git
				synced 2025-10-30 18:07:51 +00:00 
			
		
		
		
	Refactor code with Java best practices, helped by AS
This commit is contained in:
		
							parent
							
								
									2576ca7468
								
							
						
					
					
						commit
						9d61d6c732
					
				| @ -17,8 +17,6 @@ package fr.unix_experience.owncloud_sms.activities; | |||||||
|  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. |  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| import java.util.List; |  | ||||||
| 
 |  | ||||||
| import android.accounts.Account; | import android.accounts.Account; | ||||||
| import android.accounts.AccountManager; | import android.accounts.AccountManager; | ||||||
| import android.content.ContentResolver; | import android.content.ContentResolver; | ||||||
| @ -26,6 +24,9 @@ import android.content.PeriodicSync; | |||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
| import android.preference.ListPreference; | import android.preference.ListPreference; | ||||||
| import android.util.Log; | import android.util.Log; | ||||||
|  | 
 | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
| import fr.nrz.androidlib.activities.NrzSettingsActivity; | import fr.nrz.androidlib.activities.NrzSettingsActivity; | ||||||
| import fr.unix_experience.owncloud_sms.R; | import fr.unix_experience.owncloud_sms.R; | ||||||
| import fr.unix_experience.owncloud_sms.defines.DefaultPrefs; | import fr.unix_experience.owncloud_sms.defines.DefaultPrefs; | ||||||
| @ -39,87 +40,81 @@ public class GeneralSettingsActivity extends NrzSettingsActivity { | |||||||
| 	private static String _accountType; | 	private static String _accountType; | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	protected void onPostCreate(final Bundle savedInstanceState) { | 	protected void onPostCreate(Bundle savedInstanceState) { | ||||||
| 		_accountMgr = AccountManager.get(getBaseContext()); |         GeneralSettingsActivity._accountMgr = AccountManager.get(getBaseContext()); | ||||||
| 		_accountAuthority = getString(R.string.account_authority); |         GeneralSettingsActivity._accountAuthority = getString(R.string.account_authority); | ||||||
| 		_accountType = getString(R.string.account_type); |         GeneralSettingsActivity._accountType = getString(R.string.account_type); | ||||||
| 		_prefsRessourceFile = R.xml.pref_data_sync; |         NrzSettingsActivity._prefsRessourceFile = R.xml.pref_data_sync; | ||||||
| 
 | 
 | ||||||
| 		// Bind our boolean preferences | 		// Bind our boolean preferences | ||||||
| 		_boolPrefs.add(new BindObjectPref("push_on_receive", DefaultPrefs.pushOnReceive)); |         NrzSettingsActivity._boolPrefs.add(new BindObjectPref("push_on_receive", DefaultPrefs.pushOnReceive)); | ||||||
| 		_boolPrefs.add(new BindObjectPref("sync_wifi", DefaultPrefs.syncWifi)); |         NrzSettingsActivity._boolPrefs.add(new BindObjectPref("sync_wifi", DefaultPrefs.syncWifi)); | ||||||
| 		_boolPrefs.add(new BindObjectPref("sync_4g", DefaultPrefs.sync4G)); |         NrzSettingsActivity._boolPrefs.add(new BindObjectPref("sync_4g", DefaultPrefs.sync4G)); | ||||||
| 		_boolPrefs.add(new BindObjectPref("sync_3g", DefaultPrefs.sync3G)); |         NrzSettingsActivity._boolPrefs.add(new BindObjectPref("sync_3g", DefaultPrefs.sync3G)); | ||||||
| 		_boolPrefs.add(new BindObjectPref("sync_gprs", DefaultPrefs.syncGPRS)); |         NrzSettingsActivity._boolPrefs.add(new BindObjectPref("sync_gprs", DefaultPrefs.syncGPRS)); | ||||||
| 		_boolPrefs.add(new BindObjectPref("sync_2g", DefaultPrefs.sync2G)); |         NrzSettingsActivity._boolPrefs.add(new BindObjectPref("sync_2g", DefaultPrefs.sync2G)); | ||||||
| 		_boolPrefs.add(new BindObjectPref("sync_others", DefaultPrefs.syncOthers)); |         NrzSettingsActivity._boolPrefs.add(new BindObjectPref("sync_others", DefaultPrefs.syncOthers)); | ||||||
| 
 | 
 | ||||||
| 		// Bind our string preferences | 		// Bind our string preferences | ||||||
| 		_stringPrefs.add(new BindObjectPref("sync_frequency", "")); |         NrzSettingsActivity._stringPrefs.add(new BindObjectPref("sync_frequency", "")); | ||||||
| 
 | 
 | ||||||
| 		// Must be at the end, after preference bind | 		// Must be at the end, after preference bind | ||||||
| 		super.onPostCreate(savedInstanceState); | 		super.onPostCreate(savedInstanceState); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	protected static void handleCheckboxPreference(final String key, final Boolean value) { | 	protected static void handleCheckboxPreference(String key, Boolean value) { | ||||||
| 		// Network types allowed for sync | 		// Network types allowed for sync | ||||||
| 		if(key.equals(new String("push_on_receive")) || | 		if("push_on_receive".equals(key) || | ||||||
| 				key.equals(new String("sync_wifi")) || key.equals("sync_2g") || |                 "sync_wifi".equals(key) || "sync_2g".equals(key) || | ||||||
| 				key.equals(new String("sync_3g")) || key.equals("sync_gprs") || |                 "sync_3g".equals(key) || "sync_gprs".equals(key) || | ||||||
| 				key.equals("sync_4g") || key.equals("sync_others")) { |                 "sync_4g".equals(key) || "sync_others".equals(key)) { | ||||||
| 			final OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context); | 			OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(NrzSettingsActivity._context); | ||||||
| 			Log.d(TAG,"GeneralSettingsActivity.handleCheckboxPreference: set " + key + " to " | 			Log.d(GeneralSettingsActivity.TAG,"GeneralSettingsActivity.handleCheckboxPreference: set " + key + " to " | ||||||
| 					+ value.toString()); | 					+ value.toString()); | ||||||
| 			prefs.putBoolean(key, value); | 			prefs.putBoolean(key, value); | ||||||
| 		} | 		} | ||||||
| 		else { |  | ||||||
| 			// Unknown option |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	protected static void handleListPreference(final String key, final String value, | 	protected static void handleListPreference(String key, String value, | ||||||
| 			final ListPreference preference) { | 			ListPreference preference) { | ||||||
| 		// For list preferences, look up the correct display value in | 		// For list preferences, look up the correct display value in | ||||||
| 		// the preference's 'entries' list. | 		// the preference's 'entries' list. | ||||||
| 		final int index = preference.findIndexOfValue(value); | 		int index = preference.findIndexOfValue(value); | ||||||
| 
 | 
 | ||||||
| 		// Set the summary to reflect the new value. | 		// Set the summary to reflect the new value. | ||||||
| 		preference | 		preference | ||||||
| 		.setSummary(index >= 0 ? preference.getEntries()[index] | 		.setSummary((index >= 0) ? preference.getEntries()[index] | ||||||
|                 : null); |                 : null); | ||||||
| 
 | 
 | ||||||
| 		// Handle sync frequency change | 		// Handle sync frequency change | ||||||
| 		if (key.equals("sync_frequency")) { | 		if ("sync_frequency".equals(key)) { | ||||||
| 			final Account[] myAccountList = _accountMgr.getAccountsByType(_accountType); | 			Account[] myAccountList = GeneralSettingsActivity._accountMgr.getAccountsByType(GeneralSettingsActivity._accountType); | ||||||
| 			final long syncFreq = Long.parseLong(value); | 			long syncFreq = Long.parseLong(value); | ||||||
| 
 | 
 | ||||||
| 			// Get ownCloud SMS account list | 			// Get ownCloud SMS account list | ||||||
| 			for (int i = 0; i < myAccountList.length; i++) { | 			for (int i = 0; i < myAccountList.length; i++) { | ||||||
| 				// And get all authorities for this account | 				// And get all authorities for this account | ||||||
| 				final List<PeriodicSync> syncList = ContentResolver.getPeriodicSyncs(myAccountList[i], _accountAuthority); | 				List<PeriodicSync> syncList = ContentResolver.getPeriodicSyncs(myAccountList[i], GeneralSettingsActivity._accountAuthority); | ||||||
| 
 | 
 | ||||||
| 				boolean foundSameSyncCycle = false; | 				boolean foundSameSyncCycle = false; | ||||||
| 				for (int j = 0; j < syncList.size(); j++) { | 				for (int j = 0; j < syncList.size(); j++) { | ||||||
| 					final PeriodicSync ps = syncList.get(i); | 					PeriodicSync ps = syncList.get(i); | ||||||
| 
 | 
 | ||||||
| 					if (ps.period == syncFreq && ps.extras.getInt("synctype") == 1) { | 					if ((ps.period == syncFreq) && (ps.extras.getInt("synctype") == 1)) { | ||||||
| 						foundSameSyncCycle = true; | 						foundSameSyncCycle = true; | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				if (foundSameSyncCycle == false) { | 				if (!foundSameSyncCycle) { | ||||||
| 					final Bundle b = new Bundle(); | 					Bundle b = new Bundle(); | ||||||
| 					b.putInt("synctype", 1); | 					b.putInt("synctype", 1); | ||||||
| 
 | 
 | ||||||
| 					ContentResolver.removePeriodicSync(myAccountList[i], | 					ContentResolver.removePeriodicSync(myAccountList[i], | ||||||
| 							_accountAuthority, b); |                             GeneralSettingsActivity._accountAuthority, b); | ||||||
| 					ContentResolver.addPeriodicSync(myAccountList[i], | 					ContentResolver.addPeriodicSync(myAccountList[i], | ||||||
| 							_accountAuthority, b, syncFreq * 60); |                             GeneralSettingsActivity._accountAuthority, b, syncFreq * 60); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		else { |  | ||||||
| 			// Unhandled option |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -83,7 +83,7 @@ public class LoginActivity extends Activity { | |||||||
| 					@Override | 					@Override | ||||||
| 					public boolean onEditorAction(TextView textView, int id, | 					public boolean onEditorAction(TextView textView, int id, | ||||||
| 							KeyEvent keyEvent) { | 							KeyEvent keyEvent) { | ||||||
| 						if (id == R.id.oc_login || id == EditorInfo.IME_NULL) { | 						if ((id == R.id.oc_login) || (id == EditorInfo.IME_NULL)) { | ||||||
| 							attemptLogin(); | 							attemptLogin(); | ||||||
| 							return true; | 							return true; | ||||||
| 						} | 						} | ||||||
| @ -161,12 +161,14 @@ public class LoginActivity extends Activity { | |||||||
| 		if (cancel) { | 		if (cancel) { | ||||||
| 			// There was an error; don't attempt login and focus the first | 			// There was an error; don't attempt login and focus the first | ||||||
| 			// form field with an error. | 			// form field with an error. | ||||||
|  |             if (focusView != null) { | ||||||
|                 focusView.requestFocus(); |                 focusView.requestFocus(); | ||||||
|  |             } | ||||||
|         } else { |         } else { | ||||||
| 			// Show a progress spinner, and kick off a background task to | 			// Show a progress spinner, and kick off a background task to | ||||||
| 			// perform the user login attempt. | 			// perform the user login attempt. | ||||||
| 			showProgress(true); | 			showProgress(true); | ||||||
| 			String serverURL = new String(protocol + serverAddr); | 			String serverURL = protocol + serverAddr; | ||||||
| 			mAuthTask = new UserLoginTask(serverURL, login, password); | 			mAuthTask = new UserLoginTask(serverURL, login, password); | ||||||
| 			mAuthTask.execute((Void) null); | 			mAuthTask.execute((Void) null); | ||||||
| 		} | 		} | ||||||
| @ -254,12 +256,12 @@ public class LoginActivity extends Activity { | |||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		@Override | 		@Override | ||||||
| 		protected void onPostExecute(final Boolean success) { | 		protected void onPostExecute(Boolean success) { | ||||||
| 			mAuthTask = null; | 			mAuthTask = null; | ||||||
| 			showProgress(false); | 			showProgress(false); | ||||||
| 
 | 
 | ||||||
| 			if (success) { | 			if (success) { | ||||||
| 				String accountType = getIntent().getStringExtra(PARAM_AUTHTOKEN_TYPE); | 				String accountType = getIntent().getStringExtra(UserLoginTask.PARAM_AUTHTOKEN_TYPE); | ||||||
| 				if (accountType == null) {   | 				if (accountType == null) {   | ||||||
| 		            accountType = getString(R.string.account_type);   | 		            accountType = getString(R.string.account_type);   | ||||||
| 		        } | 		        } | ||||||
| @ -268,7 +270,7 @@ public class LoginActivity extends Activity { | |||||||
| 				String accountLabel = _login + "@" + _serverURI.getHost(); | 				String accountLabel = _login + "@" + _serverURI.getHost(); | ||||||
| 				 | 				 | ||||||
| 				// We create the account | 				// We create the account | ||||||
| 				final Account account = new Account(accountLabel, accountType); | 				Account account = new Account(accountLabel, accountType); | ||||||
| 				Bundle accountBundle = new Bundle(); | 				Bundle accountBundle = new Bundle(); | ||||||
| 				accountBundle.putString("ocLogin", _login); | 				accountBundle.putString("ocLogin", _login); | ||||||
| 				accountBundle.putString("ocURI", _serverURI.toString()); | 				accountBundle.putString("ocURI", _serverURI.toString()); | ||||||
| @ -293,6 +295,8 @@ public class LoginActivity extends Activity { | |||||||
| 				getApplicationContext().startActivity(settingsIntent); | 				getApplicationContext().startActivity(settingsIntent); | ||||||
| 			} else { | 			} else { | ||||||
| 				switch (_returnCode) { | 				switch (_returnCode) { | ||||||
|  |                     case OK: | ||||||
|  |                         break; | ||||||
|                     case INVALID_ADDR: |                     case INVALID_ADDR: | ||||||
| 						_serverView.setError(getString(R.string.error_invalid_server_address)); | 						_serverView.setError(getString(R.string.error_invalid_server_address)); | ||||||
| 						_serverView.requestFocus(); | 						_serverView.requestFocus(); | ||||||
| @ -332,6 +336,5 @@ public class LoginActivity extends Activity { | |||||||
| 		private LoginReturnCode _returnCode; | 		private LoginReturnCode _returnCode; | ||||||
| 		 | 		 | ||||||
| 		public static final String PARAM_AUTHTOKEN_TYPE = "auth.token"; | 		public static final String PARAM_AUTHTOKEN_TYPE = "auth.token"; | ||||||
| 	    public static final String PARAM_CREATE = "create";  |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -25,11 +25,6 @@ package fr.unix_experience.owncloud_sms.activities; | |||||||
|  * SUCH DAMAGE. |  * SUCH DAMAGE. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| import java.util.List; |  | ||||||
| import java.util.Vector; |  | ||||||
| 
 |  | ||||||
| import org.json.JSONArray; |  | ||||||
| 
 |  | ||||||
| import android.app.Activity; | import android.app.Activity; | ||||||
| import android.app.Fragment; | import android.app.Fragment; | ||||||
| import android.app.FragmentManager; | import android.app.FragmentManager; | ||||||
| @ -45,6 +40,12 @@ import android.view.LayoutInflater; | |||||||
| import android.view.View; | import android.view.View; | ||||||
| import android.view.ViewGroup; | import android.view.ViewGroup; | ||||||
| import android.widget.Toast; | import android.widget.Toast; | ||||||
|  | 
 | ||||||
|  | import org.json.JSONArray; | ||||||
|  | 
 | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Vector; | ||||||
|  | 
 | ||||||
| import fr.unix_experience.owncloud_sms.R; | import fr.unix_experience.owncloud_sms.R; | ||||||
| import fr.unix_experience.owncloud_sms.activities.remote_account.AccountListActivity; | import fr.unix_experience.owncloud_sms.activities.remote_account.AccountListActivity; | ||||||
| import fr.unix_experience.owncloud_sms.engine.ASyncSMSSync.SyncTask; | import fr.unix_experience.owncloud_sms.engine.ASyncSMSSync.SyncTask; | ||||||
| @ -69,14 +70,14 @@ public class MainActivity extends Activity { | |||||||
| 	ViewPager mViewPager; | 	ViewPager mViewPager; | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	protected void onCreate(final Bundle savedInstanceState) { | 	protected void onCreate(Bundle savedInstanceState) { | ||||||
| 		super.onCreate(savedInstanceState); | 		super.onCreate(savedInstanceState); | ||||||
| 		setContentView(R.layout.activity_main); | 		setContentView(R.layout.activity_main); | ||||||
| 
 | 
 | ||||||
| 		// Create the adapter that will return a fragment for each of the three | 		// Create the adapter that will return a fragment for each of the three | ||||||
| 		// primary sections of the activity. | 		// primary sections of the activity. | ||||||
| 
 | 
 | ||||||
| 		final List<Fragment> fragments = new Vector<Fragment>(); | 		List<Fragment> fragments = new Vector<>(); | ||||||
| 
 | 
 | ||||||
| 		/* | 		/* | ||||||
| 		 * Add the Main tabs here | 		 * Add the Main tabs here | ||||||
| @ -101,13 +102,13 @@ public class MainActivity extends Activity { | |||||||
| 
 | 
 | ||||||
| 		private final List<Fragment> mFragments; | 		private final List<Fragment> mFragments; | ||||||
| 
 | 
 | ||||||
| 		public MainPagerAdapter(final FragmentManager fragmentManager, final List<Fragment> fragments) { | 		public MainPagerAdapter(FragmentManager fragmentManager, List<Fragment> fragments) { | ||||||
| 			super(fragmentManager); | 			super(fragmentManager); | ||||||
| 			mFragments = fragments; | 			mFragments = fragments; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		@Override | 		@Override | ||||||
| 		public Fragment getItem(final int position) { | 		public Fragment getItem(int position) { | ||||||
| 			// getItem is called to instantiate the fragment for the given page. | 			// getItem is called to instantiate the fragment for the given page. | ||||||
| 			// Return a PlaceholderFragment (defined as a static inner class | 			// Return a PlaceholderFragment (defined as a static inner class | ||||||
| 			// below). | 			// below). | ||||||
| @ -126,53 +127,50 @@ public class MainActivity extends Activity { | |||||||
| 	 */ | 	 */ | ||||||
| 	public static class StarterFragment extends Fragment { | 	public static class StarterFragment extends Fragment { | ||||||
| 		@Override | 		@Override | ||||||
| 		public View onCreateView(final LayoutInflater inflater, final ViewGroup container, | 		public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||||||
| 				final Bundle savedInstanceState) { | 				Bundle savedInstanceState) { | ||||||
| 			final View rootView = inflater.inflate(R.layout.fragment_mainactivity_main, container, |             return inflater.inflate(R.layout.fragment_mainactivity_main, container, | ||||||
|                     false); |                     false); | ||||||
| 			return rootView; |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public static class SecondTestFragment extends Fragment { | 	public static class SecondTestFragment extends Fragment { | ||||||
| 		@Override | 		@Override | ||||||
| 		public View onCreateView(final LayoutInflater inflater, final ViewGroup container, | 		public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||||||
| 				final Bundle savedInstanceState) { | 				Bundle savedInstanceState) { | ||||||
| 			final View rootView = inflater.inflate(R.layout.fragment_mainactivity_gotosettings, container, |             return inflater.inflate(R.layout.fragment_mainactivity_gotosettings, container, | ||||||
|                     false); |                     false); | ||||||
| 			return rootView; |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public static class ThanksAndRateFragment extends Fragment { | 	public static class ThanksAndRateFragment extends Fragment { | ||||||
| 		@Override | 		@Override | ||||||
| 		public View onCreateView(final LayoutInflater inflater, final ViewGroup container, | 		public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||||||
| 				final Bundle savedInstanceState) { | 				Bundle savedInstanceState) { | ||||||
| 			final View rootView = inflater.inflate(R.layout.fragment_mainactivity_thanks_note, container, |             return inflater.inflate(R.layout.fragment_mainactivity_thanks_note, container, | ||||||
|                     false); |                     false); | ||||||
| 			return rootView; |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void openAppSettings(final View view) { | 	public void openAppSettings(View view) { | ||||||
| 		startActivity(new Intent(this, GeneralSettingsActivity.class)); | 		startActivity(new Intent(this, GeneralSettingsActivity.class)); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void openAddAccount(final View view) { | 	public void openAddAccount(View view) { | ||||||
| 		startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT)); | 		startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT)); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void syncAllMessages(final View view) { | 	public void syncAllMessages(View view) { | ||||||
| 		final Context ctx = getApplicationContext(); | 		Context ctx = getApplicationContext(); | ||||||
| 		final ConnectivityMonitor cMon = new ConnectivityMonitor(ctx); | 		ConnectivityMonitor cMon = new ConnectivityMonitor(ctx); | ||||||
| 
 | 
 | ||||||
| 		if (cMon.isValid()) { | 		if (cMon.isValid()) { | ||||||
| 			// Now fetch messages since last stored date | 			// Now fetch messages since last stored date | ||||||
| 			final JSONArray smsList = new SmsFetcher(ctx) | 			JSONArray smsList = new SmsFetcher(ctx) | ||||||
| 			.bufferMessagesSinceDate((long) 0); | 			.bufferMessagesSinceDate((long) 0); | ||||||
| 
 | 
 | ||||||
| 			if (smsList != null) { | 			if (smsList != null) { | ||||||
| 				final OCSMSNotificationManager nMgr = new OCSMSNotificationManager(ctx); | 				OCSMSNotificationManager nMgr = new OCSMSNotificationManager(ctx); | ||||||
| 				nMgr.setSyncProcessMsg(); | 				nMgr.setSyncProcessMsg(); | ||||||
| 				new SyncTask(getApplicationContext(), smsList).execute(); | 				new SyncTask(getApplicationContext(), smsList).execute(); | ||||||
| 			} | 			} | ||||||
| @ -182,16 +180,16 @@ public class MainActivity extends Activity { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void selectRemoteAccount(final View view) { | 	public void selectRemoteAccount(View view) { | ||||||
| 		startActivity(new Intent(this, AccountListActivity.class)); | 		startActivity(new Intent(this, AccountListActivity.class)); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void openGooglePlayStore(final View view) { | 	public void openGooglePlayStore(View view) { | ||||||
| 		Intent intent; | 		Intent intent; | ||||||
| 		try { | 		try { | ||||||
| 			intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())); | 			intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())); | ||||||
| 
 | 
 | ||||||
| 		} catch (final android.content.ActivityNotFoundException anfe) { | 		} catch (android.content.ActivityNotFoundException anfe) { | ||||||
| 			intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName())); | 			intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName())); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,23 +1,25 @@ | |||||||
| package fr.unix_experience.owncloud_sms.activities.remote_account; | package fr.unix_experience.owncloud_sms.activities.remote_account; | ||||||
| 
 | 
 | ||||||
| import java.util.ArrayList; |  | ||||||
| 
 |  | ||||||
| import android.accounts.Account; | import android.accounts.Account; | ||||||
| import android.accounts.AccountManager; | import android.accounts.AccountManager; | ||||||
| import android.app.ListActivity; | import android.app.ListActivity; | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
|  | 
 | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.Collections; | ||||||
|  | 
 | ||||||
| import fr.nrz.androidlib.adapters.AndroidAccountAdapter; | import fr.nrz.androidlib.adapters.AndroidAccountAdapter; | ||||||
| import fr.unix_experience.owncloud_sms.R; | import fr.unix_experience.owncloud_sms.R; | ||||||
| 
 | 
 | ||||||
| public class AccountListActivity extends ListActivity { | public class AccountListActivity extends ListActivity { | ||||||
| 	ArrayList<Account> listItems = new ArrayList<Account>(); | 	ArrayList<Account> listItems = new ArrayList<>(); | ||||||
| 	AndroidAccountAdapter adapter; | 	AndroidAccountAdapter adapter; | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public void onCreate(final Bundle icicle) { | 	public void onCreate(Bundle icicle) { | ||||||
| 		super.onCreate(icicle); | 		super.onCreate(icicle); | ||||||
| 
 | 
 | ||||||
| 		final AccountManager _accountMgr = AccountManager.get(getBaseContext()); | 		AccountManager _accountMgr = AccountManager.get(getBaseContext()); | ||||||
| 
 | 
 | ||||||
| 		setContentView(R.layout.restore_activity_accountlist); | 		setContentView(R.layout.restore_activity_accountlist); | ||||||
| 		adapter = new AndroidAccountAdapter(this, | 		adapter = new AndroidAccountAdapter(this, | ||||||
| @ -27,11 +29,9 @@ public class AccountListActivity extends ListActivity { | |||||||
| 				R.id.accountname, ContactListActivity.class); | 				R.id.accountname, ContactListActivity.class); | ||||||
| 		setListAdapter(adapter); | 		setListAdapter(adapter); | ||||||
| 
 | 
 | ||||||
| 		final Account[] accountList = | 		Account[] accountList = | ||||||
| 				_accountMgr.getAccountsByType(getString(R.string.account_type)); | 				_accountMgr.getAccountsByType(getString(R.string.account_type)); | ||||||
| 		for (final Account element : accountList) { |         Collections.addAll(listItems, accountList); | ||||||
| 			listItems.add(element); |  | ||||||
| 		} |  | ||||||
| 
 | 
 | ||||||
| 		adapter.notifyDataSetChanged(); | 		adapter.notifyDataSetChanged(); | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -30,19 +30,19 @@ public class ContactListActivity extends Activity implements ASyncContactLoad { | |||||||
| 	ArrayList<String> objects; | 	ArrayList<String> objects; | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	protected void onCreate(final Bundle savedInstanceState) { | 	protected void onCreate(Bundle savedInstanceState) { | ||||||
| 		super.onCreate(savedInstanceState); | 		super.onCreate(savedInstanceState); | ||||||
| 
 | 
 | ||||||
| 		assert getIntent().getExtras() != null; | 		assert getIntent().getExtras() != null; | ||||||
| 
 | 
 | ||||||
| 		final String accountName = getIntent().getExtras().getString("account"); | 		String accountName = getIntent().getExtras().getString("account"); | ||||||
| 
 | 
 | ||||||
| 		// accountName cannot be null, devel error | 		// accountName cannot be null, devel error | ||||||
| 		assert accountName != null; | 		assert accountName != null; | ||||||
| 
 | 
 | ||||||
| 		_accountMgr = AccountManager.get(getBaseContext()); |         ContactListActivity._accountMgr = AccountManager.get(getBaseContext()); | ||||||
| 		final Account[] myAccountList = | 		Account[] myAccountList = | ||||||
| 				_accountMgr.getAccountsByType(getString(R.string.account_type)); |                 ContactListActivity._accountMgr.getAccountsByType(getString(R.string.account_type)); | ||||||
| 		 | 		 | ||||||
| 		// Init view | 		// Init view | ||||||
| 		objects = new ArrayList<>(); | 		objects = new ArrayList<>(); | ||||||
| @ -79,8 +79,8 @@ public class ContactListActivity extends Activity implements ASyncContactLoad { | |||||||
| 				Integer smsCount = 0; | 				Integer smsCount = 0; | ||||||
| 				// @TODO asynctask to load more datas | 				// @TODO asynctask to load more datas | ||||||
| 
 | 
 | ||||||
| 				if (phoneList.size() > 0) { | 				if (!phoneList.isEmpty()) { | ||||||
| 					String res = new String(""); | 					String res = ""; | ||||||
| 					for (String pn: phoneList) { | 					for (String pn: phoneList) { | ||||||
| 						res += "- " + pn + "\n"; | 						res += "- " + pn + "\n"; | ||||||
| 					} | 					} | ||||||
| @ -101,6 +101,10 @@ public class ContactListActivity extends Activity implements ASyncContactLoad { | |||||||
| 				Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, | 				Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, | ||||||
| 						null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " = ?", | 						null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " = ?", | ||||||
| 						new String[]{name}, null); | 						new String[]{name}, null); | ||||||
|  |                 if (people == null) { | ||||||
|  |                     return new Vector<>(); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|                 people.moveToFirst(); |                 people.moveToFirst(); | ||||||
| 
 | 
 | ||||||
|                 Vector<String> r = new Vector<>(); |                 Vector<String> r = new Vector<>(); | ||||||
| @ -110,18 +114,20 @@ public class ContactListActivity extends Activity implements ASyncContactLoad { | |||||||
| 
 | 
 | ||||||
| 				String contactId = people.getString(people.getColumnIndex(ContactsContract.Contacts._ID)); | 				String contactId = people.getString(people.getColumnIndex(ContactsContract.Contacts._ID)); | ||||||
| 
 | 
 | ||||||
| 				if (people.getString(people.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)) | 				if ("1".equalsIgnoreCase(people.getString(people.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)))) { | ||||||
| 						.equalsIgnoreCase("1")) { |  | ||||||
| 					Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, | 					Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, | ||||||
| 							null, | 							null, | ||||||
| 							ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", | 							ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", | ||||||
| 							new String[]{contactId}, null); | 							new String[]{contactId}, null); | ||||||
| 					while (phones.moveToNext()) { | 					while ((phones != null) && phones.moveToNext()) { | ||||||
| 						String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)) | 						String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)) | ||||||
| 								.replaceAll(" ", ""); | 								.replaceAll(" ", ""); | ||||||
| 						r.add(phoneNumber); | 						r.add(phoneNumber); | ||||||
| 					} | 					} | ||||||
|  | 
 | ||||||
|  |                     if (phones != null) { | ||||||
|                         phones.close(); |                         phones.close(); | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
| 				return r; | 				return r; | ||||||
| 			} | 			} | ||||||
|  | |||||||
| @ -1,50 +1,48 @@ | |||||||
| package fr.unix_experience.owncloud_sms.adapters; | package fr.unix_experience.owncloud_sms.adapters; | ||||||
| 
 | 
 | ||||||
| import java.util.ArrayList; |  | ||||||
| 
 |  | ||||||
| import android.app.Activity; | import android.app.Activity; | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
| import android.content.Intent; |  | ||||||
| import android.view.LayoutInflater; | import android.view.LayoutInflater; | ||||||
| import android.view.View; | import android.view.View; | ||||||
| import android.view.ViewGroup; | import android.view.ViewGroup; | ||||||
| import android.view.View.OnClickListener; |  | ||||||
| import android.widget.ArrayAdapter; | import android.widget.ArrayAdapter; | ||||||
| import android.widget.TextView; | import android.widget.TextView; | ||||||
| 
 | 
 | ||||||
|  | import java.util.ArrayList; | ||||||
|  | 
 | ||||||
| public class ContactListAdapter extends ArrayAdapter<String> { | public class ContactListAdapter extends ArrayAdapter<String> { | ||||||
| 	private final ArrayList<String> _objects; | 	private final ArrayList<String> _objects; | ||||||
| 	private static int _itemLayout; | 	private static int _itemLayout; | ||||||
| 	private static int _fieldId; | 	private static int _fieldId; | ||||||
| 	private Activity _activity; | 	private final Activity _activity; | ||||||
| 	 | 	 | ||||||
| 	public ContactListAdapter(final Context context, final int resource, | 	public ContactListAdapter(Context context, int resource, | ||||||
| 				final ArrayList<String> objects, final int itemLayout, | 				ArrayList<String> objects, int itemLayout, | ||||||
| 				final int fieldId, final Activity activity) { | 				int fieldId, Activity activity) { | ||||||
| 		super(context, resource, objects); | 		super(context, resource, objects); | ||||||
| 		_objects = objects; | 		_objects = objects; | ||||||
| 		_itemLayout = itemLayout; |         ContactListAdapter._itemLayout = itemLayout; | ||||||
| 		_fieldId = fieldId; |         ContactListAdapter._fieldId = fieldId; | ||||||
| 		_activity = activity; | 		_activity = activity; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public View getView(final int position, final View convertView, final ViewGroup parent) { | 	public View getView(int position, View convertView, ViewGroup parent) { | ||||||
| 		View v = convertView; | 		View v = convertView; | ||||||
| 		if (v == null) { | 		if (v == null) { | ||||||
| 			final LayoutInflater inflater =  | 			LayoutInflater inflater = | ||||||
| 					(LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); | 					(LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); | ||||||
| 			v = inflater.inflate(_itemLayout, null); | 			v = inflater.inflate(ContactListAdapter._itemLayout, null); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if (_objects.size() == 0) { | 		if (_objects.isEmpty()) { | ||||||
| 			return null; | 			return null; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		final String element = _objects.get(position); | 		String element = _objects.get(position); | ||||||
| 
 | 
 | ||||||
| 		if (element != null) { | 		if (element != null) { | ||||||
| 			final TextView label = (TextView) v.findViewById(_fieldId); | 			TextView label = (TextView) v.findViewById(ContactListAdapter._fieldId); | ||||||
| 			if (label != null) { | 			if (label != null) { | ||||||
| 				label.setText(element); | 				label.setText(element); | ||||||
| 			} | 			} | ||||||
| @ -52,6 +50,4 @@ public class ContactListAdapter extends ArrayAdapter<String> { | |||||||
| 
 | 
 | ||||||
| 		return v; | 		return v; | ||||||
| 	} | 	} | ||||||
| 
 |  | ||||||
| 	private static final String TAG = ContactListAdapter.class.getSimpleName(); |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -17,16 +17,6 @@ package fr.unix_experience.owncloud_sms.authenticators; | |||||||
|  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. |  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| import java.io.IOException; |  | ||||||
| import org.apache.commons.httpclient.HttpException; |  | ||||||
| import org.apache.commons.httpclient.methods.GetMethod; |  | ||||||
| import org.apache.http.HttpStatus; |  | ||||||
| import org.json.JSONObject; |  | ||||||
| 
 |  | ||||||
| import com.owncloud.android.lib.common.OwnCloudClient; |  | ||||||
| 
 |  | ||||||
| import fr.unix_experience.owncloud_sms.activities.LoginActivity; |  | ||||||
| import fr.unix_experience.owncloud_sms.enums.LoginReturnCode; |  | ||||||
| import android.accounts.AbstractAccountAuthenticator; | import android.accounts.AbstractAccountAuthenticator; | ||||||
| import android.accounts.Account; | import android.accounts.Account; | ||||||
| import android.accounts.AccountAuthenticatorResponse; | import android.accounts.AccountAuthenticatorResponse; | ||||||
| @ -37,6 +27,18 @@ import android.content.Intent; | |||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
| import android.util.Log; | import android.util.Log; | ||||||
| 
 | 
 | ||||||
|  | import com.owncloud.android.lib.common.OwnCloudClient; | ||||||
|  | 
 | ||||||
|  | import org.apache.commons.httpclient.HttpException; | ||||||
|  | import org.apache.commons.httpclient.methods.GetMethod; | ||||||
|  | import org.apache.http.HttpStatus; | ||||||
|  | import org.json.JSONObject; | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | 
 | ||||||
|  | import fr.unix_experience.owncloud_sms.activities.LoginActivity; | ||||||
|  | import fr.unix_experience.owncloud_sms.enums.LoginReturnCode; | ||||||
|  | 
 | ||||||
| public class OwnCloudAuthenticator extends AbstractAccountAuthenticator { | public class OwnCloudAuthenticator extends AbstractAccountAuthenticator { | ||||||
|     // Simple constructor |     // Simple constructor | ||||||
|     public OwnCloudAuthenticator(Context context) { |     public OwnCloudAuthenticator(Context context) { | ||||||
| @ -56,8 +58,8 @@ public class OwnCloudAuthenticator extends AbstractAccountAuthenticator { | |||||||
| 			String accountType, String authTokenType, | 			String accountType, String authTokenType, | ||||||
| 			String[] requiredFeatures, Bundle options) | 			String[] requiredFeatures, Bundle options) | ||||||
| 			throws NetworkErrorException { | 			throws NetworkErrorException { | ||||||
| 		final Bundle result;   | 		Bundle result; | ||||||
| 		final Intent intent;   | 		Intent intent; | ||||||
| 		                 | 		                 | ||||||
| 		intent = new Intent(_context, LoginActivity.class);   | 		intent = new Intent(_context, LoginActivity.class);   | ||||||
| 		 | 		 | ||||||
| @ -112,8 +114,8 @@ public class OwnCloudAuthenticator extends AbstractAccountAuthenticator { | |||||||
| 	 */ | 	 */ | ||||||
| 	public LoginReturnCode testCredentials() { | 	public LoginReturnCode testCredentials() { | ||||||
| 		LoginReturnCode bRet = LoginReturnCode.OK; | 		LoginReturnCode bRet = LoginReturnCode.OK; | ||||||
| 		GetMethod get = null; | 		GetMethod get; | ||||||
| 		int status = -1; | 		int status; | ||||||
| 		 | 		 | ||||||
| 		try { | 		try { | ||||||
| 		    get = new GetMethod(_client.getBaseUri() + "/index.php/ocs/cloud/user?format=json"); | 		    get = new GetMethod(_client.getBaseUri() + "/index.php/ocs/cloud/user?format=json"); | ||||||
| @ -136,37 +138,32 @@ public class OwnCloudAuthenticator extends AbstractAccountAuthenticator { | |||||||
| 		try { | 		try { | ||||||
| 			if(isSuccess(status)) { | 			if(isSuccess(status)) { | ||||||
| 				 String response = get.getResponseBodyAsString(); | 				 String response = get.getResponseBodyAsString(); | ||||||
| 				 Log.d(TAG, "Successful response: " + response); | 				 Log.d(OwnCloudAuthenticator.TAG, "Successful response: " + response); | ||||||
| 
 | 
 | ||||||
| 				 // Parse the response | 				 // Parse the response | ||||||
| 				 JSONObject respJSON = new JSONObject(response); | 				 JSONObject respJSON = new JSONObject(response); | ||||||
| 				 JSONObject respOCS = respJSON.getJSONObject(NODE_OCS); | 				 JSONObject respOCS = respJSON.getJSONObject(OwnCloudAuthenticator.NODE_OCS); | ||||||
| 				 JSONObject respData = respOCS.getJSONObject(NODE_DATA); | 				 JSONObject respData = respOCS.getJSONObject(OwnCloudAuthenticator.NODE_DATA); | ||||||
| 				 String id = respData.getString(NODE_ID); | 				 String id = respData.getString(OwnCloudAuthenticator.NODE_ID); | ||||||
| 				 String displayName = respData.getString(NODE_DISPLAY_NAME); | 				 String displayName = respData.getString(OwnCloudAuthenticator.NODE_DISPLAY_NAME); | ||||||
| 				 String email = respData.getString(NODE_EMAIL); | 				 String email = respData.getString(OwnCloudAuthenticator.NODE_EMAIL); | ||||||
| 				  | 				  | ||||||
| 				 Log.d(TAG, "*** Parsed user information: " + id + " - " + displayName + " - " + email); | 				 Log.d(OwnCloudAuthenticator.TAG, "*** Parsed user information: " + id + " - " + displayName + " - " + email); | ||||||
| 				  | 				  | ||||||
| 			} else { | 			} else { | ||||||
| 				String response = get.getResponseBodyAsString(); | 				String response = get.getResponseBodyAsString(); | ||||||
| 				Log.e(TAG, "Failed response while getting user information "); | 				Log.e(OwnCloudAuthenticator.TAG, "Failed response while getting user information "); | ||||||
| 				if (response != null) { | 				if (response != null) { | ||||||
| 					Log.e(TAG, "*** status code: " + status + " ; response message: " + response); | 					Log.e(OwnCloudAuthenticator.TAG, "*** status code: " + status + " ; response message: " + response); | ||||||
| 				} else { | 				} else { | ||||||
| 					Log.e(TAG, "*** status code: " + status); | 					Log.e(OwnCloudAuthenticator.TAG, "*** status code: " + status); | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				if (status == 401) { |                 bRet = (status == 401) ? LoginReturnCode.INVALID_LOGIN : LoginReturnCode.UNKNOWN_ERROR; | ||||||
| 					bRet = LoginReturnCode.INVALID_LOGIN; |  | ||||||
| 				} |  | ||||||
| 				else { |  | ||||||
| 					bRet = LoginReturnCode.UNKNOWN_ERROR; |  | ||||||
| 				} |  | ||||||
| 			} | 			} | ||||||
| 			 | 			 | ||||||
| 		} catch (Exception e) { | 		} catch (Exception e) { | ||||||
| 			Log.e(TAG, "Exception while getting OC user information", e); | 			Log.e(OwnCloudAuthenticator.TAG, "Exception while getting OC user information", e); | ||||||
| 			bRet = LoginReturnCode.UNKNOWN_ERROR; | 			bRet = LoginReturnCode.UNKNOWN_ERROR; | ||||||
| 			 | 			 | ||||||
| 		} finally { | 		} finally { | ||||||
| @ -183,7 +180,7 @@ public class OwnCloudAuthenticator extends AbstractAccountAuthenticator { | |||||||
| 		_client = oc; | 		_client = oc; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private Context _context; | 	private final Context _context; | ||||||
| 	private OwnCloudClient _client; | 	private OwnCloudClient _client; | ||||||
| 	 | 	 | ||||||
| 	private static final String TAG = OwnCloudAuthenticator.class.getSimpleName(); | 	private static final String TAG = OwnCloudAuthenticator.class.getSimpleName(); | ||||||
|  | |||||||
| @ -28,20 +28,20 @@ public interface ASyncContactLoad { | |||||||
| 		private static AccountManager _accountMgr = null; | 		private static AccountManager _accountMgr = null; | ||||||
| 		private static Account _account; | 		private static Account _account; | ||||||
| 		private final Context _context; | 		private final Context _context; | ||||||
| 		private ContactListAdapter _adapter; | 		private final ContactListAdapter _adapter; | ||||||
| 		private ArrayList<String> _objects; | 		private final ArrayList<String> _objects; | ||||||
| 		private SwipeRefreshLayout _layout; | 		private final SwipeRefreshLayout _layout; | ||||||
| 		private ProgressBar _pg; | 		private final ProgressBar _pg; | ||||||
| 		private Spinner _contactSpinner; | 		private final Spinner _contactSpinner; | ||||||
| 
 | 
 | ||||||
| 		public ContactLoadTask(final Account account, final Context context, | 		public ContactLoadTask(Account account, Context context, | ||||||
| 				ContactListAdapter adapter, ArrayList<String> objects, SwipeRefreshLayout layout, | 				ContactListAdapter adapter, ArrayList<String> objects, SwipeRefreshLayout layout, | ||||||
| 				ProgressBar pg, Spinner sp) { | 				ProgressBar pg, Spinner sp) { | ||||||
| 			if (_accountMgr == null) { | 			if (ContactLoadTask._accountMgr == null) { | ||||||
| 				_accountMgr = AccountManager.get(context); |                 ContactLoadTask._accountMgr = AccountManager.get(context); | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			_account = account; |             ContactLoadTask._account = account; | ||||||
| 			_context = context; | 			_context = context; | ||||||
| 			_adapter = adapter; | 			_adapter = adapter; | ||||||
| 			_objects = objects; | 			_objects = objects; | ||||||
| @ -50,19 +50,19 @@ public interface ASyncContactLoad { | |||||||
| 			_contactSpinner = sp; | 			_contactSpinner = sp; | ||||||
| 		} | 		} | ||||||
| 		@Override | 		@Override | ||||||
| 		protected Boolean doInBackground(final Void... params) { | 		protected Boolean doInBackground(Void... params) { | ||||||
| 			// Create client | 			// Create client | ||||||
| 			final String ocURI = _accountMgr.getUserData(_account, "ocURI"); | 			String ocURI = ContactLoadTask._accountMgr.getUserData(ContactLoadTask._account, "ocURI"); | ||||||
| 			if (ocURI == null) { | 			if (ocURI == null) { | ||||||
| 				// @TODO: Handle the problem | 				// @TODO: Handle the problem | ||||||
| 				return false; | 				return false; | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			final Uri serverURI = Uri.parse(ocURI); | 			Uri serverURI = Uri.parse(ocURI); | ||||||
| 
 | 
 | ||||||
| 			final OCSMSOwnCloudClient _client = new OCSMSOwnCloudClient(_context, | 			OCSMSOwnCloudClient _client = new OCSMSOwnCloudClient(_context, | ||||||
| 					serverURI, _accountMgr.getUserData(_account, "ocLogin"), | 					serverURI, ContactLoadTask._accountMgr.getUserData(ContactLoadTask._account, "ocLogin"), | ||||||
| 					_accountMgr.getPassword(_account)); |                     ContactLoadTask._accountMgr.getPassword(ContactLoadTask._account)); | ||||||
| 
 | 
 | ||||||
| 			// Remove all objects, due to refreshing handling | 			// Remove all objects, due to refreshing handling | ||||||
| 			_objects.clear(); | 			_objects.clear(); | ||||||
| @ -84,8 +84,8 @@ public interface ASyncContactLoad { | |||||||
| 				ContentResolver cr = _context.getContentResolver(); | 				ContentResolver cr = _context.getContentResolver(); | ||||||
| 				Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, | 				Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, | ||||||
| 						null, null, null, null); | 						null, null, null, null); | ||||||
| 				if (cur.getCount() > 0) { | 				if (((cur != null) ? cur.getCount() : 0) > 0) { | ||||||
| 					while (cur.moveToNext()) { | 					while ((cur != null) && cur.moveToNext()) { | ||||||
| 						String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); | 						String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); | ||||||
| 						String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); | 						String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); | ||||||
| 						if (Integer.parseInt(cur.getString( | 						if (Integer.parseInt(cur.getString( | ||||||
| @ -97,7 +97,7 @@ public interface ASyncContactLoad { | |||||||
| 									null, | 									null, | ||||||
| 									ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", | 									ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", | ||||||
| 									new String[]{id}, null); | 									new String[]{id}, null); | ||||||
| 							while (pCur.moveToNext()) { | 							while ((pCur != null) && pCur.moveToNext()) { | ||||||
| 								String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)) | 								String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)) | ||||||
| 										.replaceAll(" ", ""); | 										.replaceAll(" ", ""); | ||||||
| 								if (serverPhoneList.contains(phoneNo)) { | 								if (serverPhoneList.contains(phoneNo)) { | ||||||
| @ -107,11 +107,15 @@ public interface ASyncContactLoad { | |||||||
| 									serverPhoneList.remove(phoneNo); | 									serverPhoneList.remove(phoneNo); | ||||||
| 								} | 								} | ||||||
| 							} | 							} | ||||||
|  |                             if (pCur != null) { | ||||||
|                                 pCur.close(); |                                 pCur.close(); | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
| 					} | 					} | ||||||
|  | 				} | ||||||
|  |                 if (cur != null) { | ||||||
|                     cur.close(); |                     cur.close(); | ||||||
|  |                 } | ||||||
| 
 | 
 | ||||||
|                 for (String phone : serverPhoneList) { |                 for (String phone : serverPhoneList) { | ||||||
| 					_objects.add(phone); | 					_objects.add(phone); | ||||||
| @ -122,14 +126,14 @@ public interface ASyncContactLoad { | |||||||
| 			} catch (JSONException e) { | 			} catch (JSONException e) { | ||||||
| 				_objects.add(_context.getString(R.string.err_fetch_phonelist)); | 				_objects.add(_context.getString(R.string.err_fetch_phonelist)); | ||||||
| 				return false; | 				return false; | ||||||
| 			} catch (final OCSyncException e) { | 			} catch (OCSyncException e) { | ||||||
| 				_objects.add(_context.getString(e.getErrorId())); | 				_objects.add(_context.getString(e.getErrorId())); | ||||||
| 				return false; | 				return false; | ||||||
| 			} | 			} | ||||||
| 			return true; | 			return true; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		protected void onPostExecute(final Boolean success) { | 		protected void onPostExecute(Boolean success) { | ||||||
| 			_adapter.notifyDataSetChanged(); | 			_adapter.notifyDataSetChanged(); | ||||||
| 			_layout.setRefreshing(false); | 			_layout.setRefreshing(false); | ||||||
| 			if (_pg != null) { | 			if (_pg != null) { | ||||||
| @ -142,5 +146,5 @@ public interface ASyncContactLoad { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	static final String TAG = ASyncContactLoad.class.getSimpleName(); | 	String TAG = ASyncContactLoad.class.getSimpleName(); | ||||||
| } | } | ||||||
|  | |||||||
| @ -17,45 +17,46 @@ package fr.unix_experience.owncloud_sms.engine; | |||||||
|  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. |  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| import org.json.JSONArray; |  | ||||||
| 
 |  | ||||||
| import android.accounts.Account; | import android.accounts.Account; | ||||||
| import android.accounts.AccountManager; | import android.accounts.AccountManager; | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
| import android.net.Uri; | import android.net.Uri; | ||||||
| import android.os.AsyncTask; | import android.os.AsyncTask; | ||||||
| import android.util.Log; | import android.util.Log; | ||||||
|  | 
 | ||||||
|  | import org.json.JSONArray; | ||||||
|  | 
 | ||||||
| import fr.unix_experience.owncloud_sms.R; | import fr.unix_experience.owncloud_sms.R; | ||||||
| import fr.unix_experience.owncloud_sms.exceptions.OCSyncException; | import fr.unix_experience.owncloud_sms.exceptions.OCSyncException; | ||||||
| import fr.unix_experience.owncloud_sms.notifications.OCSMSNotificationManager; | import fr.unix_experience.owncloud_sms.notifications.OCSMSNotificationManager; | ||||||
| 
 | 
 | ||||||
| public interface ASyncSMSSync { | public interface ASyncSMSSync { | ||||||
| 	class SyncTask extends AsyncTask<Void, Void, Void> { | 	class SyncTask extends AsyncTask<Void, Void, Void> { | ||||||
| 		public SyncTask(final Context context, final JSONArray smsList) { | 		public SyncTask(Context context, JSONArray smsList) { | ||||||
| 			_context = context; | 			_context = context; | ||||||
| 			_smsList = smsList; | 			_smsList = smsList; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		@Override | 		@Override | ||||||
| 		protected Void doInBackground(final Void... params) { | 		protected Void doInBackground(Void... params) { | ||||||
| 			// Get ownCloud SMS account list | 			// Get ownCloud SMS account list | ||||||
| 			final AccountManager _accountMgr = AccountManager.get(_context); | 			AccountManager _accountMgr = AccountManager.get(_context); | ||||||
| 			final Account[] myAccountList = _accountMgr.getAccountsByType(_context.getString(R.string.account_type)); | 			Account[] myAccountList = _accountMgr.getAccountsByType(_context.getString(R.string.account_type)); | ||||||
| 
 | 
 | ||||||
| 			// Notify that we are syncing SMS | 			// Notify that we are syncing SMS | ||||||
| 			final OCSMSNotificationManager nMgr = new OCSMSNotificationManager(_context); | 			OCSMSNotificationManager nMgr = new OCSMSNotificationManager(_context); | ||||||
| 			for (final Account element : myAccountList) { | 			for (Account element : myAccountList) { | ||||||
| 				final Uri serverURI = Uri.parse(_accountMgr.getUserData(element, "ocURI")); | 				Uri serverURI = Uri.parse(_accountMgr.getUserData(element, "ocURI")); | ||||||
| 
 | 
 | ||||||
| 				final OCSMSOwnCloudClient _client = new OCSMSOwnCloudClient(_context, | 				OCSMSOwnCloudClient _client = new OCSMSOwnCloudClient(_context, | ||||||
| 						serverURI, _accountMgr.getUserData(element, "ocLogin"), | 						serverURI, _accountMgr.getUserData(element, "ocLogin"), | ||||||
| 						_accountMgr.getPassword(element)); | 						_accountMgr.getPassword(element)); | ||||||
| 
 | 
 | ||||||
| 				try { | 				try { | ||||||
| 					_client.doPushRequest(_smsList); | 					_client.doPushRequest(_smsList); | ||||||
| 					nMgr.dropSyncErrorMsg(); | 					nMgr.dropSyncErrorMsg(); | ||||||
| 				} catch (final OCSyncException e) { | 				} catch (OCSyncException e) { | ||||||
| 					Log.e(TAG, _context.getString(e.getErrorId())); | 					Log.e(ASyncSMSSync.TAG, _context.getString(e.getErrorId())); | ||||||
| 					nMgr.setSyncErrorMsg(_context.getString(e.getErrorId())); | 					nMgr.setSyncErrorMsg(_context.getString(e.getErrorId())); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| @ -67,5 +68,5 @@ public interface ASyncSMSSync { | |||||||
| 		private final JSONArray _smsList; | 		private final JSONArray _smsList; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	static final String TAG = ASyncSMSSync.class.getSimpleName(); | 	String TAG = ASyncSMSSync.class.getSimpleName(); | ||||||
| } | } | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ import android.telephony.TelephonyManager; | |||||||
| import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs; | import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs; | ||||||
| 
 | 
 | ||||||
| public class ConnectivityMonitor { | public class ConnectivityMonitor { | ||||||
| 	public ConnectivityMonitor(final Context context) { | 	public ConnectivityMonitor(Context context) { | ||||||
| 		_context = context; | 		_context = context; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -33,17 +33,17 @@ public class ConnectivityMonitor { | |||||||
| 			_cMgr = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE); | 			_cMgr = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		final android.net.NetworkInfo niWiFi = _cMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); | 		android.net.NetworkInfo niWiFi = _cMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); | ||||||
| 		final android.net.NetworkInfo niMobile = _cMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); | 		android.net.NetworkInfo niMobile = _cMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); | ||||||
| 
 | 
 | ||||||
| 		if (niWiFi.isAvailable() || niMobile.isAvailable()) { | 		if (niWiFi.isAvailable() || niMobile.isAvailable()) { | ||||||
| 			// Load the connectivity manager to determine on which network we are connected | 			// Load the connectivity manager to determine on which network we are connected | ||||||
| 			final NetworkInfo netInfo = _cMgr.getActiveNetworkInfo(); | 			NetworkInfo netInfo = _cMgr.getActiveNetworkInfo(); | ||||||
| 			if (netInfo == null) { | 			if (netInfo == null) { | ||||||
| 				return false; | 				return false; | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			final OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context); | 			OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context); | ||||||
| 
 | 
 | ||||||
| 			// Check | 			// Check | ||||||
| 			switch (netInfo.getType()) { | 			switch (netInfo.getType()) { | ||||||
|  | |||||||
| @ -17,9 +17,13 @@ package fr.unix_experience.owncloud_sms.engine; | |||||||
|  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. |  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| import java.io.IOException; | import android.content.Context; | ||||||
| import java.io.UnsupportedEncodingException; | import android.net.Uri; | ||||||
| import java.net.ConnectException; | import android.util.Log; | ||||||
|  | 
 | ||||||
|  | import com.owncloud.android.lib.common.OwnCloudClient; | ||||||
|  | import com.owncloud.android.lib.common.OwnCloudClientFactory; | ||||||
|  | import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; | ||||||
| 
 | 
 | ||||||
| import org.apache.commons.httpclient.HttpException; | import org.apache.commons.httpclient.HttpException; | ||||||
| import org.apache.commons.httpclient.HttpMethod; | import org.apache.commons.httpclient.HttpMethod; | ||||||
| @ -31,13 +35,9 @@ import org.json.JSONArray; | |||||||
| import org.json.JSONException; | import org.json.JSONException; | ||||||
| import org.json.JSONObject; | import org.json.JSONObject; | ||||||
| 
 | 
 | ||||||
| import android.content.Context; | import java.io.IOException; | ||||||
| import android.net.Uri; | import java.io.UnsupportedEncodingException; | ||||||
| import android.util.Log; | import java.net.ConnectException; | ||||||
| 
 |  | ||||||
| import com.owncloud.android.lib.common.OwnCloudClient; |  | ||||||
| import com.owncloud.android.lib.common.OwnCloudClientFactory; |  | ||||||
| import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; |  | ||||||
| 
 | 
 | ||||||
| import fr.unix_experience.owncloud_sms.R; | import fr.unix_experience.owncloud_sms.R; | ||||||
| import fr.unix_experience.owncloud_sms.enums.OCSyncErrorType; | import fr.unix_experience.owncloud_sms.enums.OCSyncErrorType; | ||||||
| @ -47,7 +47,7 @@ import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs; | |||||||
| @SuppressWarnings("deprecation") | @SuppressWarnings("deprecation") | ||||||
| public class OCSMSOwnCloudClient { | public class OCSMSOwnCloudClient { | ||||||
| 
 | 
 | ||||||
| 	public OCSMSOwnCloudClient(final Context context, final Uri serverURI, final String accountName, final String accountPassword) { | 	public OCSMSOwnCloudClient(Context context, Uri serverURI, String accountName, String accountPassword) { | ||||||
| 		_context = context; | 		_context = context; | ||||||
| 
 | 
 | ||||||
| 		_ocClient = OwnCloudClientFactory.createOwnCloudClient( | 		_ocClient = OwnCloudClientFactory.createOwnCloudClient( | ||||||
| @ -62,8 +62,8 @@ public class OCSMSOwnCloudClient { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public Integer getServerAPIVersion() throws OCSyncException { | 	public Integer getServerAPIVersion() throws OCSyncException { | ||||||
| 		final GetMethod get = createGetVersionRequest(); | 		GetMethod get = createGetVersionRequest(); | ||||||
| 		final JSONObject obj = doHttpRequest(get, true); | 		JSONObject obj = doHttpRequest(get, true); | ||||||
| 		if (obj == null) { | 		if (obj == null) { | ||||||
| 			// Return default version | 			// Return default version | ||||||
| 			return 1; | 			return 1; | ||||||
| @ -72,8 +72,8 @@ public class OCSMSOwnCloudClient { | |||||||
| 		try { | 		try { | ||||||
| 			_serverAPIVersion = obj.getInt("version"); | 			_serverAPIVersion = obj.getInt("version"); | ||||||
| 		} | 		} | ||||||
| 		catch (final JSONException e) { | 		catch (JSONException e) { | ||||||
| 			Log.e(TAG, "No version received from server, assuming version 1", e); | 			Log.e(OCSMSOwnCloudClient.TAG, "No version received from server, assuming version 1", e); | ||||||
| 			_serverAPIVersion = 1; | 			_serverAPIVersion = 1; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| @ -81,21 +81,21 @@ public class OCSMSOwnCloudClient { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public JSONArray getServerPhoneNumbers() throws OCSyncException { | 	public JSONArray getServerPhoneNumbers() throws OCSyncException { | ||||||
| 		final GetMethod get = createGetPhoneListRequest(); | 		GetMethod get = createGetPhoneListRequest(); | ||||||
| 		final JSONObject obj = doHttpRequest(get, true); | 		JSONObject obj = doHttpRequest(get, true); | ||||||
| 		if (obj == null) { | 		if (obj == null) { | ||||||
| 			return null; | 			return null; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		try { | 		try { | ||||||
| 			return obj.getJSONArray("phoneList"); | 			return obj.getJSONArray("phoneList"); | ||||||
| 		} catch (final JSONException e) { | 		} catch (JSONException e) { | ||||||
| 			Log.e(TAG, "No phonelist received from server, empty it", e); | 			Log.e(OCSMSOwnCloudClient.TAG, "No phonelist received from server, empty it", e); | ||||||
| 			return null; | 			return null; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void doPushRequest(final JSONArray smsList) throws OCSyncException { | 	public void doPushRequest(JSONArray smsList) throws OCSyncException { | ||||||
| 		/** | 		/** | ||||||
| 		 * If we need other API push, set it here | 		 * If we need other API push, set it here | ||||||
| 		 */ | 		 */ | ||||||
| @ -110,8 +110,8 @@ public class OCSMSOwnCloudClient { | |||||||
| 		Long lastMsgDate = (long) 0; | 		Long lastMsgDate = (long) 0; | ||||||
| 
 | 
 | ||||||
| 		if (smsList == null) { | 		if (smsList == null) { | ||||||
| 			final GetMethod get = createGetSmsIdListRequest(); | 			GetMethod get = createGetSmsIdListRequest(); | ||||||
| 			final JSONObject smsGetObj = doHttpRequest(get); | 			JSONObject smsGetObj = doHttpRequest(get); | ||||||
| 			if (smsGetObj == null) { | 			if (smsGetObj == null) { | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| @ -120,34 +120,34 @@ public class OCSMSOwnCloudClient { | |||||||
| 			JSONArray inboxSmsList = null, sentSmsList = null, draftsSmsList = null; | 			JSONArray inboxSmsList = null, sentSmsList = null, draftsSmsList = null; | ||||||
| 			try { | 			try { | ||||||
| 				smsBoxes = smsGetObj.getJSONObject("smslist"); | 				smsBoxes = smsGetObj.getJSONObject("smslist"); | ||||||
| 			} catch (final JSONException e) { | 			} catch (JSONException e) { | ||||||
| 				try { | 				try { | ||||||
| 					smsGetObj.getJSONArray("smslist"); | 					smsGetObj.getJSONArray("smslist"); | ||||||
| 				} catch (final JSONException e2) { | 				} catch (JSONException e2) { | ||||||
| 					Log.e(TAG, "Invalid datas received from server (doPushRequest, get SMS list)", e); | 					Log.e(OCSMSOwnCloudClient.TAG, "Invalid datas received from server (doPushRequest, get SMS list)", e); | ||||||
| 					throw new OCSyncException(R.string.err_sync_get_smslist, OCSyncErrorType.PARSE); | 					throw new OCSyncException(R.string.err_sync_get_smslist, OCSyncErrorType.PARSE); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			try { | 			try { | ||||||
| 				inboxSmsList = smsBoxes.getJSONArray("inbox"); | 				inboxSmsList = smsBoxes.getJSONArray("inbox"); | ||||||
| 			} catch (final JSONException e) { | 			} catch (JSONException e) { | ||||||
| 				Log.d(TAG, "No inbox Sms received from server (doPushRequest, get SMS list)"); | 				Log.d(OCSMSOwnCloudClient.TAG, "No inbox Sms received from server (doPushRequest, get SMS list)"); | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			try { | 			try { | ||||||
| 				sentSmsList = smsBoxes.getJSONArray("sent"); | 				sentSmsList = smsBoxes.getJSONArray("sent"); | ||||||
| 			} catch (final JSONException e) { | 			} catch (JSONException e) { | ||||||
| 				Log.d(TAG, "No sent Sms received from server (doPushRequest, get SMS list)"); | 				Log.d(OCSMSOwnCloudClient.TAG, "No sent Sms received from server (doPushRequest, get SMS list)"); | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			try { | 			try { | ||||||
| 				draftsSmsList = smsBoxes.getJSONArray("drafts"); | 				draftsSmsList = smsBoxes.getJSONArray("drafts"); | ||||||
| 			} catch (final JSONException e) { | 			} catch (JSONException e) { | ||||||
| 				Log.d(TAG, "No drafts Sms received from server (doPushRequest, get SMS list)"); | 				Log.d(OCSMSOwnCloudClient.TAG, "No drafts Sms received from server (doPushRequest, get SMS list)"); | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			final SmsFetcher fetcher = new SmsFetcher(_context); | 			SmsFetcher fetcher = new SmsFetcher(_context); | ||||||
| 			fetcher.setExistingInboxMessages(inboxSmsList); | 			fetcher.setExistingInboxMessages(inboxSmsList); | ||||||
| 			fetcher.setExistingSentMessages(sentSmsList); | 			fetcher.setExistingSentMessages(sentSmsList); | ||||||
| 			fetcher.setExistingDraftsMessages(draftsSmsList); | 			fetcher.setExistingDraftsMessages(draftsSmsList); | ||||||
| @ -159,19 +159,19 @@ public class OCSMSOwnCloudClient { | |||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if (smsList.length() == 0) { | 		if (smsList.length() == 0) { | ||||||
| 			Log.d(TAG, "No new SMS to sync, sync done"); | 			Log.d(OCSMSOwnCloudClient.TAG, "No new SMS to sync, sync done"); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		final PostMethod post = createPushRequest(smsList); | 		PostMethod post = createPushRequest(smsList); | ||||||
| 		if (post == null) { | 		if (post == null) { | ||||||
| 			Log.e(TAG,"Push request for POST is null"); | 			Log.e(OCSMSOwnCloudClient.TAG,"Push request for POST is null"); | ||||||
| 			throw new OCSyncException(R.string.err_sync_craft_http_request, OCSyncErrorType.IO); | 			throw new OCSyncException(R.string.err_sync_craft_http_request, OCSyncErrorType.IO); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		final JSONObject obj = doHttpRequest(post); | 		JSONObject obj = doHttpRequest(post); | ||||||
| 		if (obj == null) { | 		if (obj == null) { | ||||||
| 			Log.e(TAG,"Request failed. It doesn't return a valid JSON Object"); | 			Log.e(OCSMSOwnCloudClient.TAG,"Request failed. It doesn't return a valid JSON Object"); | ||||||
| 			throw new OCSyncException(R.string.err_sync_push_request, OCSyncErrorType.IO); | 			throw new OCSyncException(R.string.err_sync_push_request, OCSyncErrorType.IO); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| @ -181,87 +181,81 @@ public class OCSMSOwnCloudClient { | |||||||
| 			pushStatus = obj.getBoolean("status"); | 			pushStatus = obj.getBoolean("status"); | ||||||
| 			pushMessage = obj.getString("msg"); | 			pushMessage = obj.getString("msg"); | ||||||
| 		} | 		} | ||||||
| 		catch (final JSONException e) { | 		catch (JSONException e) { | ||||||
| 			Log.e(TAG, "Invalid datas received from server", e); | 			Log.e(OCSMSOwnCloudClient.TAG, "Invalid datas received from server", e); | ||||||
| 			throw new OCSyncException(R.string.err_sync_push_request_resp, OCSyncErrorType.PARSE); | 			throw new OCSyncException(R.string.err_sync_push_request_resp, OCSyncErrorType.PARSE); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		// Push was OK, we can save the lastMessageDate which was saved to server | 		// Push was OK, we can save the lastMessageDate which was saved to server | ||||||
| 		(new OCSMSSharedPrefs(_context)).setLastMessageDate(lastMsgDate); | 		(new OCSMSSharedPrefs(_context)).setLastMessageDate(lastMsgDate); | ||||||
| 
 | 
 | ||||||
| 		Log.d(TAG, "SMS Push request said: status " + pushStatus + " - " + pushMessage); | 		Log.d(OCSMSOwnCloudClient.TAG, "SMS Push request said: status " + pushStatus + " - " + pushMessage); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public GetMethod createGetVersionRequest() { | 	public GetMethod createGetVersionRequest() { | ||||||
| 		return createGetRequest(OC_GET_VERSION); | 		return createGetRequest(OCSMSOwnCloudClient.OC_GET_VERSION); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public GetMethod createGetPhoneListRequest() { | 	public GetMethod createGetPhoneListRequest() { | ||||||
| 		return createGetRequest(OC_GET_PHONELIST); | 		return createGetRequest(OCSMSOwnCloudClient.OC_GET_PHONELIST); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public GetMethod createGetSmsIdListRequest() { | 	public GetMethod createGetSmsIdListRequest() { | ||||||
| 		return createGetRequest(OC_GET_ALL_SMS_IDS); | 		return createGetRequest(OCSMSOwnCloudClient.OC_GET_ALL_SMS_IDS); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public GetMethod createGetSmsIdListWithStateRequest() { | 	public GetMethod createGetSmsIdListWithStateRequest() { | ||||||
| 		return createGetRequest(OC_GET_ALL_SMS_IDS_WITH_STATUS); | 		return createGetRequest(OCSMSOwnCloudClient.OC_GET_ALL_SMS_IDS_WITH_STATUS); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public GetMethod createGetLastSmsTimestampRequest() { | 	public GetMethod createGetLastSmsTimestampRequest() { | ||||||
| 		return createGetRequest(OC_GET_LAST_MSG_TIMESTAMP); | 		return createGetRequest(OCSMSOwnCloudClient.OC_GET_LAST_MSG_TIMESTAMP); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private GetMethod createGetRequest(final String oc_call) { | 	private GetMethod createGetRequest(String oc_call) { | ||||||
| 		final GetMethod get = new GetMethod(_ocClient.getBaseUri() + oc_call); | 		GetMethod get = new GetMethod(_ocClient.getBaseUri() + oc_call); | ||||||
| 		get.addRequestHeader("OCS-APIREQUEST", "true"); | 		get.addRequestHeader("OCS-APIREQUEST", "true"); | ||||||
| 		return get; | 		return get; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public PostMethod createPushRequest() throws OCSyncException { |     public PostMethod createPushRequest(JSONArray smsList) throws OCSyncException { | ||||||
| 		final SmsFetcher fetcher = new SmsFetcher(_context); | 		JSONObject obj = createPushJSONObject(smsList); | ||||||
| 		final JSONArray smsList = fetcher.fetchAllMessages(); |  | ||||||
| 		return createPushRequest(smsList); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public PostMethod createPushRequest(final JSONArray smsList) throws OCSyncException { |  | ||||||
| 		final JSONObject obj = createPushJSONObject(smsList); |  | ||||||
| 		if (obj == null) { | 		if (obj == null) { | ||||||
| 			return null; | 			return null; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		final StringRequestEntity ent = createJSONRequestEntity(obj); | 		StringRequestEntity ent = createJSONRequestEntity(obj); | ||||||
| 		if (ent == null) { | 		if (ent == null) { | ||||||
| 			return null; | 			return null; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		final PostMethod post = new PostMethod(_ocClient.getBaseUri() + OC_PUSH_ROUTE); | 		PostMethod post = new PostMethod(_ocClient.getBaseUri() + OCSMSOwnCloudClient.OC_PUSH_ROUTE); | ||||||
| 		post.addRequestHeader("OCS-APIREQUEST", "true"); | 		post.addRequestHeader("OCS-APIREQUEST", "true"); | ||||||
| 		post.setRequestEntity(ent); | 		post.setRequestEntity(ent); | ||||||
| 
 | 
 | ||||||
| 		return post; | 		return post; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private JSONObject createPushJSONObject(final JSONArray smsList) throws OCSyncException { | 	private JSONObject createPushJSONObject(JSONArray smsList) throws OCSyncException { | ||||||
| 		if (smsList == null) { | 		if (smsList == null) { | ||||||
| 			Log.e(TAG,"NULL SMS List"); | 			Log.e(OCSMSOwnCloudClient.TAG,"NULL SMS List"); | ||||||
| 			throw new OCSyncException(R.string.err_sync_create_json_null_smslist, OCSyncErrorType.IO); | 			throw new OCSyncException(R.string.err_sync_create_json_null_smslist, OCSyncErrorType.IO); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		final JSONObject reqJSON = new JSONObject(); | 		JSONObject reqJSON = new JSONObject(); | ||||||
| 
 | 
 | ||||||
| 		try { | 		try { | ||||||
| 			reqJSON.put("smsDatas", smsList); | 			reqJSON.put("smsDatas", smsList); | ||||||
| 			reqJSON.put("smsCount", smsList == null ? 0 : smsList.length()); | 			reqJSON.put("smsCount", smsList.length()); | ||||||
| 		} catch (final JSONException e) { | 		} catch (JSONException e) { | ||||||
| 			Log.e(TAG,"JSON Exception when creating JSON request object"); | 			Log.e(OCSMSOwnCloudClient.TAG,"JSON Exception when creating JSON request object"); | ||||||
| 			throw new OCSyncException(R.string.err_sync_create_json_put_smslist, OCSyncErrorType.PARSE); | 			throw new OCSyncException(R.string.err_sync_create_json_put_smslist, OCSyncErrorType.PARSE); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		return reqJSON; | 		return reqJSON; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private StringRequestEntity createJSONRequestEntity(final JSONObject obj) throws OCSyncException { | 	private StringRequestEntity createJSONRequestEntity(JSONObject obj) throws OCSyncException { | ||||||
| 		StringRequestEntity requestEntity; | 		StringRequestEntity requestEntity; | ||||||
| 		try { | 		try { | ||||||
| 			requestEntity = new StringRequestEntity( | 			requestEntity = new StringRequestEntity( | ||||||
| @ -269,32 +263,32 @@ public class OCSMSOwnCloudClient { | |||||||
| 					"application/json", | 					"application/json", | ||||||
| 					"UTF-8"); | 					"UTF-8"); | ||||||
| 
 | 
 | ||||||
| 		} catch (final UnsupportedEncodingException e) { | 		} catch (UnsupportedEncodingException e) { | ||||||
| 			Log.e(TAG,"Unsupported encoding when generating request"); | 			Log.e(OCSMSOwnCloudClient.TAG,"Unsupported encoding when generating request"); | ||||||
| 			throw new OCSyncException(R.string.err_sync_create_json_request_encoding, OCSyncErrorType.PARSE); | 			throw new OCSyncException(R.string.err_sync_create_json_request_encoding, OCSyncErrorType.PARSE); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		return requestEntity; | 		return requestEntity; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private JSONObject doHttpRequest(final HttpMethod req) throws OCSyncException { | 	private JSONObject doHttpRequest(HttpMethod req) throws OCSyncException { | ||||||
| 		return doHttpRequest(req, false); | 		return doHttpRequest(req, false); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// skipError permit to skip invalid JSON datas | 	// skipError permit to skip invalid JSON datas | ||||||
| 	private JSONObject doHttpRequest(final HttpMethod req, final Boolean skipError) throws OCSyncException { | 	private JSONObject doHttpRequest(HttpMethod req, Boolean skipError) throws OCSyncException { | ||||||
| 		JSONObject respJSON = null; | 		JSONObject respJSON; | ||||||
| 		int status = 0; | 		int status = 0; | ||||||
| 
 | 
 | ||||||
| 		// We try maximumHttpReqTries because sometimes network is slow or unstable | 		// We try maximumHttpReqTries because sometimes network is slow or unstable | ||||||
| 		int tryNb = 0; | 		int tryNb = 0; | ||||||
| 		final ConnectivityMonitor cMon = new ConnectivityMonitor(_context); | 		ConnectivityMonitor cMon = new ConnectivityMonitor(_context); | ||||||
| 
 | 
 | ||||||
| 		while (tryNb < maximumHttpReqTries) { | 		while (tryNb < OCSMSOwnCloudClient.maximumHttpReqTries) { | ||||||
| 			tryNb++; | 			tryNb++; | ||||||
| 
 | 
 | ||||||
| 			if (!cMon.isValid()) { | 			if (!cMon.isValid()) { | ||||||
| 				if (tryNb == maximumHttpReqTries) { | 				if (tryNb == OCSMSOwnCloudClient.maximumHttpReqTries) { | ||||||
| 					req.releaseConnection(); | 					req.releaseConnection(); | ||||||
| 					throw new OCSyncException(R.string.err_sync_no_connection_available, OCSyncErrorType.IO); | 					throw new OCSyncException(R.string.err_sync_no_connection_available, OCSyncErrorType.IO); | ||||||
| 				} | 				} | ||||||
| @ -304,31 +298,31 @@ public class OCSMSOwnCloudClient { | |||||||
| 			try { | 			try { | ||||||
| 				status = _ocClient.executeMethod(req); | 				status = _ocClient.executeMethod(req); | ||||||
| 
 | 
 | ||||||
| 				Log.d(TAG, "HTTP Request done at try " + tryNb); | 				Log.d(OCSMSOwnCloudClient.TAG, "HTTP Request done at try " + tryNb); | ||||||
| 
 | 
 | ||||||
| 				// Force loop exit | 				// Force loop exit | ||||||
| 				tryNb = maximumHttpReqTries; | 				tryNb = OCSMSOwnCloudClient.maximumHttpReqTries; | ||||||
| 			} catch (final ConnectException e) { | 			} catch (ConnectException e) { | ||||||
| 				Log.e(TAG, "Unable to perform a connection to ownCloud instance", e); | 				Log.e(OCSMSOwnCloudClient.TAG, "Unable to perform a connection to ownCloud instance", e); | ||||||
| 
 | 
 | ||||||
| 				// If it's the last try | 				// If it's the last try | ||||||
| 				if (tryNb == maximumHttpReqTries) { | 				if (tryNb == OCSMSOwnCloudClient.maximumHttpReqTries) { | ||||||
| 					req.releaseConnection(); | 					req.releaseConnection(); | ||||||
| 					throw new OCSyncException(R.string.err_sync_http_request_connect, OCSyncErrorType.IO); | 					throw new OCSyncException(R.string.err_sync_http_request_connect, OCSyncErrorType.IO); | ||||||
| 				} | 				} | ||||||
| 			} catch (final HttpException e) { | 			} catch (HttpException e) { | ||||||
| 				Log.e(TAG, "Unable to perform a connection to ownCloud instance", e); | 				Log.e(OCSMSOwnCloudClient.TAG, "Unable to perform a connection to ownCloud instance", e); | ||||||
| 
 | 
 | ||||||
| 				// If it's the last try | 				// If it's the last try | ||||||
| 				if (tryNb == maximumHttpReqTries) { | 				if (tryNb == OCSMSOwnCloudClient.maximumHttpReqTries) { | ||||||
| 					req.releaseConnection(); | 					req.releaseConnection(); | ||||||
| 					throw new OCSyncException(R.string.err_sync_http_request_httpexception, OCSyncErrorType.IO); | 					throw new OCSyncException(R.string.err_sync_http_request_httpexception, OCSyncErrorType.IO); | ||||||
| 				} | 				} | ||||||
| 			} catch (final IOException e) { | 			} catch (IOException e) { | ||||||
| 				Log.e(TAG, "Unable to perform a connection to ownCloud instance", e); | 				Log.e(OCSMSOwnCloudClient.TAG, "Unable to perform a connection to ownCloud instance", e); | ||||||
| 
 | 
 | ||||||
| 				// If it's the last try | 				// If it's the last try | ||||||
| 				if (tryNb == maximumHttpReqTries) { | 				if (tryNb == OCSMSOwnCloudClient.maximumHttpReqTries) { | ||||||
| 					req.releaseConnection(); | 					req.releaseConnection(); | ||||||
| 					throw new OCSyncException(R.string.err_sync_http_request_ioexception, OCSyncErrorType.IO); | 					throw new OCSyncException(R.string.err_sync_http_request_ioexception, OCSyncErrorType.IO); | ||||||
| 				} | 				} | ||||||
| @ -336,11 +330,11 @@ public class OCSMSOwnCloudClient { | |||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if(status == HttpStatus.SC_OK) { | 		if(status == HttpStatus.SC_OK) { | ||||||
| 			String response = null; | 			String response; | ||||||
| 			try { | 			try { | ||||||
| 				response = req.getResponseBodyAsString(); | 				response = req.getResponseBodyAsString(); | ||||||
| 			} catch (final IOException e) { | 			} catch (IOException e) { | ||||||
| 				Log.e(TAG, "Unable to parse server response", e); | 				Log.e(OCSMSOwnCloudClient.TAG, "Unable to parse server response", e); | ||||||
| 				throw new OCSyncException(R.string.err_sync_http_request_resp, OCSyncErrorType.IO); | 				throw new OCSyncException(R.string.err_sync_http_request_resp, OCSyncErrorType.IO); | ||||||
| 			} | 			} | ||||||
| 			//Log.d(TAG, "Successful response: " + response); | 			//Log.d(TAG, "Successful response: " + response); | ||||||
| @ -348,15 +342,15 @@ public class OCSMSOwnCloudClient { | |||||||
| 			// Parse the response | 			// Parse the response | ||||||
| 			try { | 			try { | ||||||
| 				respJSON = new JSONObject(response); | 				respJSON = new JSONObject(response); | ||||||
| 			} catch (final JSONException e) { | 			} catch (JSONException e) { | ||||||
| 				if (skipError == false) { | 				if (!skipError) { | ||||||
| 					if (response.contains("ownCloud") && response.contains("DOCTYPE")) { | 					if (response.contains("ownCloud") && response.contains("DOCTYPE")) { | ||||||
| 						Log.e(TAG, "OcSMS app not enabled or ownCloud upgrade is required"); | 						Log.e(OCSMSOwnCloudClient.TAG, "OcSMS app not enabled or ownCloud upgrade is required"); | ||||||
| 						throw new OCSyncException(R.string.err_sync_ocsms_not_installed_or_oc_upgrade_required, | 						throw new OCSyncException(R.string.err_sync_ocsms_not_installed_or_oc_upgrade_required, | ||||||
| 								OCSyncErrorType.SERVER_ERROR); | 								OCSyncErrorType.SERVER_ERROR); | ||||||
| 					} | 					} | ||||||
| 					else { | 					else { | ||||||
| 						Log.e(TAG, "Unable to parse server response", e); | 						Log.e(OCSMSOwnCloudClient.TAG, "Unable to parse server response", e); | ||||||
| 						throw new OCSyncException(R.string.err_sync_http_request_parse_resp, OCSyncErrorType.PARSE); | 						throw new OCSyncException(R.string.err_sync_http_request_parse_resp, OCSyncErrorType.PARSE); | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| @ -368,40 +362,38 @@ public class OCSMSOwnCloudClient { | |||||||
| 			throw new OCSyncException(R.string.err_sync_auth_failed, OCSyncErrorType.AUTH); | 			throw new OCSyncException(R.string.err_sync_auth_failed, OCSyncErrorType.AUTH); | ||||||
| 		} else { | 		} else { | ||||||
| 			// Unk error | 			// Unk error | ||||||
| 			String response = null; | 			String response; | ||||||
| 			try { | 			try { | ||||||
| 				response = req.getResponseBodyAsString(); | 				response = req.getResponseBodyAsString(); | ||||||
| 			} catch (final IOException e) { | 			} catch (IOException e) { | ||||||
| 				Log.e(TAG, "Unable to parse server response", e); | 				Log.e(OCSMSOwnCloudClient.TAG, "Unable to parse server response", e); | ||||||
| 				throw new OCSyncException(R.string.err_sync_http_request_resp, OCSyncErrorType.PARSE); | 				throw new OCSyncException(R.string.err_sync_http_request_resp, OCSyncErrorType.PARSE); | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			Log.e(TAG, "Server set unhandled HTTP return code " + status); | 			Log.e(OCSMSOwnCloudClient.TAG, "Server set unhandled HTTP return code " + status); | ||||||
| 			if (response != null) { | 			if (response != null) { | ||||||
| 				Log.e(TAG, "Status code: " + status + ". Response message: " + response); | 				Log.e(OCSMSOwnCloudClient.TAG, "Status code: " + status + ". Response message: " + response); | ||||||
| 			} else { | 			} else { | ||||||
| 				Log.e(TAG, "Status code: " + status); | 				Log.e(OCSMSOwnCloudClient.TAG, "Status code: " + status); | ||||||
| 			} | 			} | ||||||
| 			throw new OCSyncException(R.string.err_sync_http_request_returncode_unhandled, OCSyncErrorType.SERVER_ERROR); | 			throw new OCSyncException(R.string.err_sync_http_request_returncode_unhandled, OCSyncErrorType.SERVER_ERROR); | ||||||
| 		} | 		} | ||||||
| 		return respJSON; | 		return respJSON; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public OwnCloudClient getOCClient() { return _ocClient; } |     private static final int maximumHttpReqTries = 3; | ||||||
| 
 |  | ||||||
| 	private static int maximumHttpReqTries = 3; |  | ||||||
| 
 | 
 | ||||||
| 	private final OwnCloudClient _ocClient; | 	private final OwnCloudClient _ocClient; | ||||||
| 	private final Context _context; | 	private final Context _context; | ||||||
| 
 | 
 | ||||||
| 	private Integer _serverAPIVersion; | 	private Integer _serverAPIVersion; | ||||||
| 
 | 
 | ||||||
| 	private static String OC_GET_VERSION = "/index.php/apps/ocsms/get/apiversion?format=json"; | 	private static final String OC_GET_VERSION = "/index.php/apps/ocsms/get/apiversion?format=json"; | ||||||
| 	private static String OC_GET_ALL_SMS_IDS = "/index.php/apps/ocsms/get/smsidlist?format=json"; | 	private static final String OC_GET_ALL_SMS_IDS = "/index.php/apps/ocsms/get/smsidlist?format=json"; | ||||||
| 	private static String OC_GET_ALL_SMS_IDS_WITH_STATUS = "/index.php/apps/ocsms/get/smsidstate?format=json"; | 	private static final String OC_GET_ALL_SMS_IDS_WITH_STATUS = "/index.php/apps/ocsms/get/smsidstate?format=json"; | ||||||
| 	private static String OC_GET_LAST_MSG_TIMESTAMP = "/index.php/apps/ocsms/get/lastmsgtime?format=json"; | 	private static final String OC_GET_LAST_MSG_TIMESTAMP = "/index.php/apps/ocsms/get/lastmsgtime?format=json"; | ||||||
| 	private static String OC_PUSH_ROUTE = "/index.php/apps/ocsms/push?format=json"; | 	private static final String OC_PUSH_ROUTE = "/index.php/apps/ocsms/push?format=json"; | ||||||
| 	private static String OC_GET_PHONELIST = "/index.php/apps/ocsms/get/phones/numberlist?format=json"; | 	private static final String OC_GET_PHONELIST = "/index.php/apps/ocsms/get/phones/numberlist?format=json"; | ||||||
| 
 | 
 | ||||||
| 	private static final String TAG = OCSMSOwnCloudClient.class.getSimpleName(); | 	private static final String TAG = OCSMSOwnCloudClient.class.getSimpleName(); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -17,15 +17,16 @@ package fr.unix_experience.owncloud_sms.engine; | |||||||
|  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. |  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | import android.content.Context; | ||||||
|  | import android.database.Cursor; | ||||||
|  | import android.util.Log; | ||||||
|  | 
 | ||||||
| import org.json.JSONArray; | import org.json.JSONArray; | ||||||
| import org.json.JSONException; | import org.json.JSONException; | ||||||
| import org.json.JSONObject; | import org.json.JSONObject; | ||||||
| 
 | 
 | ||||||
| import fr.unix_experience.owncloud_sms.enums.MailboxID; | import fr.unix_experience.owncloud_sms.enums.MailboxID; | ||||||
| import fr.unix_experience.owncloud_sms.providers.SmsDataProvider; | import fr.unix_experience.owncloud_sms.providers.SmsDataProvider; | ||||||
| import android.content.Context; |  | ||||||
| import android.database.Cursor; |  | ||||||
| import android.util.Log; |  | ||||||
| 
 | 
 | ||||||
| public class SmsFetcher { | public class SmsFetcher { | ||||||
| 	public SmsFetcher(Context ct) { | 	public SmsFetcher(Context ct) { | ||||||
| @ -48,13 +49,13 @@ public class SmsFetcher { | |||||||
| 	private void bufferMailboxMessages(MailboxID mbID) { | 	private void bufferMailboxMessages(MailboxID mbID) { | ||||||
| 		String mbURI = mapMailboxIDToURI(mbID); | 		String mbURI = mapMailboxIDToURI(mbID); | ||||||
| 		 | 		 | ||||||
| 		if (_context == null || mbURI == null) { | 		if ((_context == null) || (mbURI == null)) { | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		if (mbID != MailboxID.INBOX && mbID != MailboxID.SENT && | 		if ((mbID != MailboxID.INBOX) && (mbID != MailboxID.SENT) && | ||||||
| 			mbID != MailboxID.DRAFTS) { |                 (mbID != MailboxID.DRAFTS)) { | ||||||
| 			Log.e(TAG,"Unhandled MailboxID " + mbID.ordinal()); | 			Log.e(SmsFetcher.TAG,"Unhandled MailboxID " + mbID.ordinal()); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| @ -64,7 +65,7 @@ public class SmsFetcher { | |||||||
| 		Cursor c = new SmsDataProvider(_context).queryNonExistingMessages(mbURI, existingIDs); | 		Cursor c = new SmsDataProvider(_context).queryNonExistingMessages(mbURI, existingIDs); | ||||||
| 
 | 
 | ||||||
|         // Reading mailbox |         // Reading mailbox | ||||||
| 		if (c != null && c.getCount() > 0) { | 		if ((c != null) && (c.getCount() > 0)) { | ||||||
| 			c.moveToFirst(); | 			c.moveToFirst(); | ||||||
| 			do { | 			do { | ||||||
| 				JSONObject entry = new JSONObject(); | 				JSONObject entry = new JSONObject(); | ||||||
| @ -82,12 +83,12 @@ public class SmsFetcher { | |||||||
|                             // Seen and read must be pseudo boolean |                             // Seen and read must be pseudo boolean | ||||||
|                             case "read": |                             case "read": | ||||||
|                             case "seen": |                             case "seen": | ||||||
|                                 entry.put(colName, c.getInt(idx) > 0 ? "true" : "false"); |                                 entry.put(colName, (c.getInt(idx) > 0) ? "true" : "false"); | ||||||
|                                 break; |                                 break; | ||||||
|                             default: |                             default: | ||||||
|                                 // Special case for date, we need to record last without searching |                                 // Special case for date, we need to record last without searching | ||||||
|                                 if (colName.equals("date")) { |                                 if ("date".equals(colName)) { | ||||||
|                                     final Long tmpDate = c.getLong(idx); |                                     Long tmpDate = c.getLong(idx); | ||||||
|                                     if (tmpDate > _lastMsgDate) { |                                     if (tmpDate > _lastMsgDate) { | ||||||
|                                         _lastMsgDate = tmpDate; |                                         _lastMsgDate = tmpDate; | ||||||
|                                     } |                                     } | ||||||
| @ -103,13 +104,13 @@ public class SmsFetcher { | |||||||
| 					_jsonDataDump.put(entry); | 					_jsonDataDump.put(entry); | ||||||
| 
 | 
 | ||||||
| 				} catch (JSONException e) { | 				} catch (JSONException e) { | ||||||
| 					Log.e(TAG, "JSON Exception when reading SMS Mailbox", e); | 					Log.e(SmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e); | ||||||
| 					c.close(); | 					c.close(); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			while(c.moveToNext()); | 			while(c.moveToNext()); | ||||||
| 
 | 
 | ||||||
| 			Log.d(TAG, c.getCount() + " messages read from " + mbURI); | 			Log.d(SmsFetcher.TAG, c.getCount() + " messages read from " + mbURI); | ||||||
| 
 | 
 | ||||||
| 			c.close(); | 			c.close(); | ||||||
| 		} | 		} | ||||||
| @ -119,7 +120,7 @@ public class SmsFetcher { | |||||||
| 	public JSONArray getLastMessage(MailboxID mbID) { | 	public JSONArray getLastMessage(MailboxID mbID) { | ||||||
| 		String mbURI = mapMailboxIDToURI(mbID); | 		String mbURI = mapMailboxIDToURI(mbID); | ||||||
| 		 | 		 | ||||||
| 		if (_context == null || mbURI == null) { | 		if ((_context == null) || (mbURI == null)) { | ||||||
| 			return null; | 			return null; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| @ -146,7 +147,7 @@ public class SmsFetcher { | |||||||
|                     // Seen and read must be pseudo boolean |                     // Seen and read must be pseudo boolean | ||||||
|                     case "read": |                     case "read": | ||||||
|                     case "seen": |                     case "seen": | ||||||
|                         entry.put(colName, c.getInt(idx) > 0 ? "true" : "false"); |                         entry.put(colName, (c.getInt(idx) > 0) ? "true" : "false"); | ||||||
|                         break; |                         break; | ||||||
|                     case "type": |                     case "type": | ||||||
|                         mboxId = c.getInt(idx); |                         mboxId = c.getInt(idx); | ||||||
| @ -167,7 +168,7 @@ public class SmsFetcher { | |||||||
| 			 | 			 | ||||||
| 			results.put(entry); | 			results.put(entry); | ||||||
| 		} catch (JSONException e) { | 		} catch (JSONException e) { | ||||||
| 			Log.e(TAG, "JSON Exception when reading SMS Mailbox", e); | 			Log.e(SmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e); | ||||||
| 			c.close(); | 			c.close(); | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| @ -189,14 +190,14 @@ public class SmsFetcher { | |||||||
| 	public void bufferMessagesSinceDate(MailboxID mbID, Long sinceDate) { | 	public void bufferMessagesSinceDate(MailboxID mbID, Long sinceDate) { | ||||||
| 		String mbURI = mapMailboxIDToURI(mbID); | 		String mbURI = mapMailboxIDToURI(mbID); | ||||||
| 		 | 		 | ||||||
| 		if (_context == null || mbURI == null) { | 		if ((_context == null) || (mbURI == null)) { | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		Cursor c = new SmsDataProvider(_context).query(mbURI, "date > ?", new String[] { sinceDate.toString() }); | 		Cursor c = new SmsDataProvider(_context).query(mbURI, "date > ?", new String[] { sinceDate.toString() }); | ||||||
| 		 | 		 | ||||||
| 		// Reading mailbox | 		// Reading mailbox | ||||||
| 		if (c != null && c.getCount() > 0) { | 		if ((c != null) && (c.getCount() > 0)) { | ||||||
| 			c.moveToFirst(); | 			c.moveToFirst(); | ||||||
| 			do { | 			do { | ||||||
| 				JSONObject entry = new JSONObject(); | 				JSONObject entry = new JSONObject(); | ||||||
| @ -214,12 +215,12 @@ public class SmsFetcher { | |||||||
|                             // Seen and read must be pseudo boolean |                             // Seen and read must be pseudo boolean | ||||||
|                             case "read": |                             case "read": | ||||||
|                             case "seen": |                             case "seen": | ||||||
|                                 entry.put(colName, c.getInt(idx) > 0 ? "true" : "false"); |                                 entry.put(colName, (c.getInt(idx) > 0) ? "true" : "false"); | ||||||
|                                 break; |                                 break; | ||||||
|                             default: |                             default: | ||||||
|                                 // Special case for date, we need to record last without searching |                                 // Special case for date, we need to record last without searching | ||||||
|                                 if (colName.equals("date")) { |                                 if ("date".equals(colName)) { | ||||||
|                                     final Long tmpDate = c.getLong(idx); |                                     Long tmpDate = c.getLong(idx); | ||||||
|                                     if (tmpDate > _lastMsgDate) { |                                     if (tmpDate > _lastMsgDate) { | ||||||
|                                         _lastMsgDate = tmpDate; |                                         _lastMsgDate = tmpDate; | ||||||
|                                     } |                                     } | ||||||
| @ -235,13 +236,13 @@ public class SmsFetcher { | |||||||
| 					_jsonDataDump.put(entry); | 					_jsonDataDump.put(entry); | ||||||
| 					 | 					 | ||||||
| 				} catch (JSONException e) { | 				} catch (JSONException e) { | ||||||
| 					Log.e(TAG, "JSON Exception when reading SMS Mailbox", e); | 					Log.e(SmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e); | ||||||
| 					c.close(); | 					c.close(); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			while(c.moveToNext()); | 			while(c.moveToNext()); | ||||||
| 			 | 			 | ||||||
| 			Log.d(TAG, c.getCount() + " messages read from " + mbURI); | 			Log.d(SmsFetcher.TAG, c.getCount() + " messages read from " + mbURI); | ||||||
| 			 | 			 | ||||||
| 			c.close(); | 			c.close(); | ||||||
| 		} | 		} | ||||||
| @ -309,7 +310,7 @@ public class SmsFetcher { | |||||||
| 		return _lastMsgDate; | 		return _lastMsgDate; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	private Context _context; | 	private final Context _context; | ||||||
| 	private JSONArray _jsonDataDump; | 	private JSONArray _jsonDataDump; | ||||||
| 	private JSONArray _existingInboxMessages; | 	private JSONArray _existingInboxMessages; | ||||||
| 	private JSONArray _existingSentMessages; | 	private JSONArray _existingSentMessages; | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ import fr.unix_experience.owncloud_sms.enums.OCSMSNotificationType; | |||||||
| 
 | 
 | ||||||
| public class OCSMSNotificationManager { | public class OCSMSNotificationManager { | ||||||
| 
 | 
 | ||||||
| 	public OCSMSNotificationManager(final Context context) { | 	public OCSMSNotificationManager(Context context) { | ||||||
| 		_context = context; | 		_context = context; | ||||||
| 		_notification = new NrzNotification(_context, R.drawable.ic_stat_ocsms); | 		_notification = new NrzNotification(_context, R.drawable.ic_stat_ocsms); | ||||||
| 	} | 	} | ||||||
| @ -40,7 +40,7 @@ public class OCSMSNotificationManager { | |||||||
| 		_notification.cancelNotify(OCSMSNotificationType.SYNC.ordinal()); | 		_notification.cancelNotify(OCSMSNotificationType.SYNC.ordinal()); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void setSyncErrorMsg(final String errMsg) { | 	public void setSyncErrorMsg(String errMsg) { | ||||||
| 		createNotificationIfPossible(OCSMSNotificationType.SYNC_FAILED, | 		createNotificationIfPossible(OCSMSNotificationType.SYNC_FAILED, | ||||||
| 				_context.getString(R.string.sync_title), | 				_context.getString(R.string.sync_title), | ||||||
| 				_context.getString(R.string.fatal_error) + "\n" + errMsg | 				_context.getString(R.string.fatal_error) + "\n" + errMsg | ||||||
| @ -51,13 +51,13 @@ public class OCSMSNotificationManager { | |||||||
| 		_notification.cancelNotify(OCSMSNotificationType.SYNC_FAILED.ordinal()); | 		_notification.cancelNotify(OCSMSNotificationType.SYNC_FAILED.ordinal()); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void setDebugMsg(final String errMsg) { | 	public void setDebugMsg(String errMsg) { | ||||||
| 		createNotificationIfPossible(OCSMSNotificationType.DEBUG, | 		createNotificationIfPossible(OCSMSNotificationType.DEBUG, | ||||||
| 				"DEBUG", errMsg | 				"DEBUG", errMsg | ||||||
| 				); | 				); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private void createNotificationIfPossible(final OCSMSNotificationType nType, final String nTitle, final String nMsg) { | 	private void createNotificationIfPossible(OCSMSNotificationType nType, String nTitle, String nMsg) { | ||||||
| 		_notification.createNotify(nType.ordinal(), nTitle, nMsg); | 		_notification.createNotify(nType.ordinal(), nTitle, nMsg); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -17,6 +17,13 @@ package fr.unix_experience.owncloud_sms.observers; | |||||||
|  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. |  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | import android.accounts.Account; | ||||||
|  | import android.accounts.AccountManager; | ||||||
|  | import android.content.Context; | ||||||
|  | import android.database.ContentObserver; | ||||||
|  | import android.os.Handler; | ||||||
|  | import android.util.Log; | ||||||
|  | 
 | ||||||
| import org.json.JSONArray; | import org.json.JSONArray; | ||||||
| 
 | 
 | ||||||
| import fr.unix_experience.owncloud_sms.R; | import fr.unix_experience.owncloud_sms.R; | ||||||
| @ -26,13 +33,6 @@ import fr.unix_experience.owncloud_sms.engine.OCSMSOwnCloudClient; | |||||||
| import fr.unix_experience.owncloud_sms.engine.SmsFetcher; | import fr.unix_experience.owncloud_sms.engine.SmsFetcher; | ||||||
| import fr.unix_experience.owncloud_sms.enums.MailboxID; | import fr.unix_experience.owncloud_sms.enums.MailboxID; | ||||||
| 
 | 
 | ||||||
| import android.accounts.Account; |  | ||||||
| import android.accounts.AccountManager; |  | ||||||
| import android.content.Context; |  | ||||||
| import android.database.ContentObserver; |  | ||||||
| import android.os.Handler; |  | ||||||
| import android.util.Log; |  | ||||||
| 
 |  | ||||||
| public class SmsObserver extends ContentObserver implements ASyncSMSSync { | public class SmsObserver extends ContentObserver implements ASyncSMSSync { | ||||||
| 
 | 
 | ||||||
| 	public SmsObserver(Handler handler) { | 	public SmsObserver(Handler handler) { | ||||||
| @ -46,10 +46,10 @@ public class SmsObserver extends ContentObserver implements ASyncSMSSync { | |||||||
| 	 | 	 | ||||||
| 	public void onChange(boolean selfChange) { | 	public void onChange(boolean selfChange) { | ||||||
| 		super.onChange(selfChange); | 		super.onChange(selfChange); | ||||||
| 		Log.d(TAG, "onChange SmsObserver"); | 		Log.d(SmsObserver.TAG, "onChange SmsObserver"); | ||||||
| 
 | 
 | ||||||
| 		// No account, abort | 		// No account, abort | ||||||
| 		final Account[] myAccountList = AccountManager.get(_context). | 		Account[] myAccountList = AccountManager.get(_context). | ||||||
| 				getAccountsByType(_context.getString(R.string.account_type)); | 				getAccountsByType(_context.getString(R.string.account_type)); | ||||||
| 		if (myAccountList.length == 0) { | 		if (myAccountList.length == 0) { | ||||||
| 			return; | 			return; | ||||||
| @ -61,7 +61,7 @@ public class SmsObserver extends ContentObserver implements ASyncSMSSync { | |||||||
| 		ConnectivityMonitor cMon = new ConnectivityMonitor(_context); | 		ConnectivityMonitor cMon = new ConnectivityMonitor(_context); | ||||||
| 		 | 		 | ||||||
| 		// Synchronize if network is valid and there are SMS | 		// Synchronize if network is valid and there are SMS | ||||||
| 		if (cMon.isValid() && smsList != null) { | 		if (cMon.isValid() && (smsList != null)) { | ||||||
| 			new SyncTask(_context, smsList).execute(); | 			new SyncTask(_context, smsList).execute(); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -25,14 +25,14 @@ import fr.unix_experience.owncloud_sms.defines.DefaultPrefs; | |||||||
| 
 | 
 | ||||||
| public class OCSMSSharedPrefs extends SharedPrefs { | public class OCSMSSharedPrefs extends SharedPrefs { | ||||||
| 
 | 
 | ||||||
| 	public OCSMSSharedPrefs(final Context context) { | 	public OCSMSSharedPrefs(Context context) { | ||||||
| 		super(context, R.string.shared_preference_file); | 		super(context, R.string.shared_preference_file); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void setLastMessageDate(final Long msgDate) { | 	public void setLastMessageDate(Long msgDate) { | ||||||
| 		final SharedPreferences.Editor editor = _sPrefs.edit(); | 		SharedPreferences.Editor editor = _sPrefs.edit(); | ||||||
| 		editor.putLong(_context.getString(R.string.pref_lastmsgdate), msgDate); | 		editor.putLong(_context.getString(R.string.pref_lastmsgdate), msgDate); | ||||||
| 		editor.commit(); | 		editor.apply(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public Long getLastMessageDate() { | 	public Long getLastMessageDate() { | ||||||
|  | |||||||
| @ -22,11 +22,12 @@ import android.content.ContentValues; | |||||||
| import android.content.Context; | import android.content.Context; | ||||||
| import android.database.Cursor; | import android.database.Cursor; | ||||||
| import android.net.Uri; | import android.net.Uri; | ||||||
|  | import android.support.annotation.NonNull; | ||||||
| 
 | 
 | ||||||
| public class SmsDataProvider extends ContentProvider { | public class SmsDataProvider extends ContentProvider { | ||||||
| 	public SmsDataProvider () {} | 	public SmsDataProvider () {} | ||||||
| 
 | 
 | ||||||
| 	public SmsDataProvider (final Context ct) { | 	public SmsDataProvider (Context ct) { | ||||||
| 		super(); | 		super(); | ||||||
| 		_context = ct; | 		_context = ct; | ||||||
| 	} | 	} | ||||||
| @ -36,29 +37,29 @@ public class SmsDataProvider extends ContentProvider { | |||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public Cursor query(final String mailBox) { | 	public Cursor query(String mailBox) { | ||||||
| 		return query(Uri.parse(mailBox), | 		return query(Uri.parse(mailBox), | ||||||
| 				new String[] { "read", "date", "address", "seen", "body", "_id", "type", }, | 				new String[] { "read", "date", "address", "seen", "body", "_id", "type", }, | ||||||
| 				null, null, null | 				null, null, null | ||||||
| 				); | 				); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public Cursor query(final String mailBox, final String selection) { | 	public Cursor query(String mailBox, String selection) { | ||||||
| 		return query(Uri.parse(mailBox), | 		return query(Uri.parse(mailBox), | ||||||
| 				new String[] { "read", "date", "address", "seen", "body", "_id", "type", }, | 				new String[] { "read", "date", "address", "seen", "body", "_id", "type", }, | ||||||
| 				selection, null, null | 				selection, null, null | ||||||
| 				); | 				); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public Cursor queryNonExistingMessages(final String mailBox, final String existingIds) { | 	public Cursor queryNonExistingMessages(String mailBox, String existingIds) { | ||||||
| 		if (existingIds.length() > 0) { | 		if (!existingIds.isEmpty()) { | ||||||
| 			return query(mailBox, "_id NOT IN (" + existingIds + ")"); | 			return query(mailBox, "_id NOT IN (" + existingIds + ")"); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		return query(mailBox); | 		return query(mailBox); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public Cursor query(final String mailBox, final String selection, final String[] selectionArgs) { | 	public Cursor query(String mailBox, String selection, String[] selectionArgs) { | ||||||
| 		return query(Uri.parse(mailBox), | 		return query(Uri.parse(mailBox), | ||||||
| 				new String[] { "read", "date", "address", "seen", "body", "_id", "type", }, | 				new String[] { "read", "date", "address", "seen", "body", "_id", "type", }, | ||||||
| 				selection, selectionArgs, null | 				selection, selectionArgs, null | ||||||
| @ -66,9 +67,9 @@ public class SmsDataProvider extends ContentProvider { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public Cursor query(final Uri uri, final String[] projection, final String selection, | 	public Cursor query(@NonNull Uri uri, String[] projection, String selection, | ||||||
| 			final String[] selectionArgs, final String sortOrder) { | 			String[] selectionArgs, String sortOrder) { | ||||||
| 		if (_context != null && _context.getContentResolver() != null) { | 		if ((_context != null) && (_context.getContentResolver() != null)) { | ||||||
| 			return _context.getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder); | 			return _context.getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| @ -76,26 +77,26 @@ public class SmsDataProvider extends ContentProvider { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public String getType(final Uri uri) { | 	public String getType(@NonNull Uri uri) { | ||||||
| 		// TODO Auto-generated method stub | 		// TODO Auto-generated method stub | ||||||
| 		return null; | 		return null; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public Uri insert(final Uri uri, final ContentValues values) { | 	public Uri insert(@NonNull Uri uri, ContentValues values) { | ||||||
| 		// TODO Auto-generated method stub | 		// TODO Auto-generated method stub | ||||||
| 		return null; | 		return null; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public int delete(final Uri uri, final String selection, final String[] selectionArgs) { | 	public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) { | ||||||
| 		// TODO Auto-generated method stub | 		// TODO Auto-generated method stub | ||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public int update(final Uri uri, final ContentValues values, final String selection, | 	public int update(@NonNull Uri uri, ContentValues values, String selection, | ||||||
| 			final String[] selectionArgs) { | 			String[] selectionArgs) { | ||||||
| 		// TODO Auto-generated method stub | 		// TODO Auto-generated method stub | ||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -44,9 +44,9 @@ public class SmsSyncService extends Service { | |||||||
|          * Set the sync adapter as syncable |          * Set the sync adapter as syncable | ||||||
|          * Disallow parallel syncs |          * Disallow parallel syncs | ||||||
|          */ |          */ | ||||||
|         synchronized (sSyncAdapterLock) { |         synchronized (SmsSyncService.sSyncAdapterLock) { | ||||||
|             if (_adapter == null) { |             if (SmsSyncService._adapter == null) { | ||||||
|             	_adapter = new SmsSyncAdapter(getApplicationContext(), true); |                 SmsSyncService._adapter = new SmsSyncAdapter(getApplicationContext(), true); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -63,6 +63,6 @@ public class SmsSyncService extends Service { | |||||||
|          * in the base class code when the SyncAdapter |          * in the base class code when the SyncAdapter | ||||||
|          * constructors call super() |          * constructors call super() | ||||||
|          */ |          */ | ||||||
|         return _adapter.getSyncAdapterBinder(); |         return SmsSyncService._adapter.getSyncAdapterBinder(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user