1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2025-06-07 16:06:18 +00:00

Change a little bit account menu to show actions to do on an account & do some code cleanups

This commit is contained in:
Loic Blot 2016-07-21 23:28:15 +02:00
parent c27a57eda4
commit 6203b8b989
13 changed files with 193 additions and 30 deletions

View File

@ -3,7 +3,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.1.0' classpath 'com.android.tools.build:gradle:2.1.2'
} }
} }

View File

@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="37" android:versionCode="37"
android:versionName="0.21.2"> <!-- From Android 4.0 to 6.0 --> android:versionName="0.21.2"> <!-- From Android 4.0 to 6.0 -->
<uses-sdk android:maxSdkVersion="23" /> <uses-sdk android:maxSdkVersion="23"/>
<uses-permission android:name="android.permission.READ_SMS"/> <uses-permission android:name="android.permission.READ_SMS"/>
<!-- For SMS Broadcaster --> <!-- For SMS Broadcaster -->
@ -105,6 +105,14 @@
android:name=".activities.remote_account.ContactListActivity" android:name=".activities.remote_account.ContactListActivity"
android:label="@string/title_activity_select_contact"> android:label="@string/title_activity_select_contact">
</activity> </activity>
<activity
android:name=".activities.remote_account.AccountActionsActivity"
android:label="@string/account_actions">
</activity>
<activity
android:name=".activities.remote_account.RestoreMessagesActivity"
android:label="@string/restore_all_messages">
</activity>
</application> </application>
</manifest> </manifest>

View File

@ -0,0 +1,49 @@
package fr.unix_experience.owncloud_sms.activities.remote_account;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import fr.unix_experience.android_lib.AppCompatListActivity;
import fr.unix_experience.owncloud_sms.R;
public class AccountActionsActivity extends AppCompatListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account_actions);
ArrayList<String> itemList = new ArrayList<>();
ArrayAdapter<String> adp = new ArrayAdapter<>(getBaseContext(),
android.R.layout.simple_dropdown_item_1line, itemList);
setListAdapter(adp);
// Create item list
itemList.add(getBaseContext().getString(R.string.restore_all_messages));
adp.notifyDataSetChanged();
// Fetch account name from intent
_accountName = getIntent().getStringExtra("account");
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
switch (position) {
case 0:
Intent intent = new Intent(this, RestoreMessagesActivity.class);
intent.putExtra("account", _accountName);
startActivity(intent);
break;
default: break; // Unhandled
}
}
private String _accountName = "";
private static final String TAG = AccountActionsActivity.class.getSimpleName();
}

View File

@ -12,8 +12,7 @@ import fr.unix_experience.android_lib.AppCompatListActivity;
import fr.unix_experience.owncloud_sms.R; import fr.unix_experience.owncloud_sms.R;
public class AccountListActivity extends AppCompatListActivity { public class AccountListActivity extends AppCompatListActivity {
ArrayList<Account> listItems = new ArrayList<>();
AndroidAccountAdapter adapter;
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
@ -22,16 +21,18 @@ public class AccountListActivity extends AppCompatListActivity {
setContentView(R.layout.restore_activity_accountlist); setContentView(R.layout.restore_activity_accountlist);
adapter = new AndroidAccountAdapter(this, ArrayList<Account> itemList = new ArrayList<>();
AndroidAccountAdapter adapter = new AndroidAccountAdapter(this,
android.R.layout.simple_list_item_1, android.R.layout.simple_list_item_1,
listItems, itemList,
R.layout.account_list_item, R.layout.account_list_item,
R.id.accountname, ContactListActivity.class); R.id.accountname, AccountActionsActivity.class);
setListAdapter(adapter); setListAdapter(adapter);
Account[] accountList = Account[] accountList =
_accountMgr.getAccountsByType(getString(R.string.account_type)); _accountMgr.getAccountsByType(getString(R.string.account_type));
Collections.addAll(listItems, accountList); Collections.addAll(itemList, accountList);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();

View File

@ -69,13 +69,15 @@ public class ContactListActivity extends AppCompatActivity implements ASyncConta
final Spinner sp = (Spinner) findViewById(R.id.contact_spinner); final Spinner sp = (Spinner) findViewById(R.id.contact_spinner);
mContactInfos = (LinearLayout) findViewById(R.id.contactinfos_layout); mContactInfos = (LinearLayout) findViewById(R.id.contactinfos_layout);
final ProgressBar contactProgressBar = (ProgressBar) findViewById(R.id.contactlist_pgbar); final ProgressBar contactProgressBar = (ProgressBar) findViewById(R.id.contactlist_pgbar);
final ListView contactPhoneListView = (ListView) findViewById(R.id.contact_phonelistView); ListView contactPhoneListView = (ListView) findViewById(R.id.contact_phonelistView);
mContactPhoneListAdapter = new RecoveryPhoneNumberListViewAdapter(getBaseContext()); mContactPhoneListAdapter = new RecoveryPhoneNumberListViewAdapter(getBaseContext());
assert contactPhoneListView != null;
contactPhoneListView.setAdapter(mContactPhoneListAdapter); contactPhoneListView.setAdapter(mContactPhoneListAdapter);
mContactInfos.setVisibility(View.INVISIBLE); mContactInfos.setVisibility(View.INVISIBLE);
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { assert sp != null;
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
mContactInfos.setVisibility(View.INVISIBLE); mContactInfos.setVisibility(View.INVISIBLE);
@ -97,7 +99,8 @@ public class ContactListActivity extends AppCompatActivity implements ASyncConta
for (final Account element : myAccountList) { for (final Account element : myAccountList) {
if (element.name.equals(accountName)) { if (element.name.equals(accountName)) {
// Load "contacts" // Load "contacts"
contactProgressBar.setVisibility(View.VISIBLE); assert contactProgressBar != null;
contactProgressBar.setVisibility(View.VISIBLE);
new ContactLoadTask(element, getBaseContext(), mAdapter, mObjects, mLayout, contactProgressBar, mContactInfos).execute(); new ContactLoadTask(element, getBaseContext(), mAdapter, mObjects, mLayout, contactProgressBar, mContactInfos).execute();
// Add refresh handler // Add refresh handler

View File

@ -0,0 +1,15 @@
package fr.unix_experience.owncloud_sms.activities.remote_account;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import fr.unix_experience.owncloud_sms.R;
public class RestoreMessagesActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_restore_messages);
}
}

View File

@ -34,19 +34,19 @@ public class OCSMSNotificationUI {
* *
* @see #cancel(Context) * @see #cancel(Context)
*/ */
public static void notify(final Context context, final String titleString, public static void notify(Context context, String titleString,
final String contentString, final int number) { String contentString, int number) {
final Resources res = context.getResources(); Resources res = context.getResources();
// This image is used as the notification's large icon (thumbnail). // This image is used as the notification's large icon (thumbnail).
// TODO: Remove this if your notification has no relevant thumbnail. // TODO: Remove this if your notification has no relevant thumbnail.
final Bitmap picture = BitmapFactory.decodeResource(res, R.drawable.ic_launcher); Bitmap picture = BitmapFactory.decodeResource(res, R.drawable.ic_launcher);
final String ticker = (titleString.length() > 20) ? titleString.substring(0, 20) : titleString; String ticker = (titleString.length() > 20) ? titleString.substring(0, 20) : titleString;
final String title = res.getString(R.string.ui_notification_title_template, titleString); String title = res.getString(R.string.ui_notification_title_template, titleString);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
// Set appropriate defaults for the notification light, sound, // Set appropriate defaults for the notification light, sound,
// and vibration. // and vibration.
@ -76,17 +76,17 @@ public class OCSMSNotificationUI {
.setSummaryText(titleString)) .setSummaryText(titleString))
.setAutoCancel(true); .setAutoCancel(true);
notify(context, builder.build()); OCSMSNotificationUI.notify(context, builder.build());
} }
@TargetApi(Build.VERSION_CODES.ECLAIR) @TargetApi(Build.VERSION_CODES.ECLAIR)
private static void notify(final Context context, final Notification notification) { private static void notify(Context context, Notification notification) {
final NotificationManager nm = (NotificationManager) context NotificationManager nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE); .getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
nm.notify(NOTIFICATION_TAG, 0, notification); nm.notify(OCSMSNotificationUI.NOTIFICATION_TAG, 0, notification);
} else { } else {
nm.notify(NOTIFICATION_TAG.hashCode(), notification); nm.notify(OCSMSNotificationUI.NOTIFICATION_TAG.hashCode(), notification);
} }
} }
@ -95,13 +95,13 @@ public class OCSMSNotificationUI {
* {@link #notify(Context, String, int)}. * {@link #notify(Context, String, int)}.
*/ */
@TargetApi(Build.VERSION_CODES.ECLAIR) @TargetApi(Build.VERSION_CODES.ECLAIR)
public static void cancel(final Context context) { public static void cancel(Context context) {
final NotificationManager nm = (NotificationManager) context NotificationManager nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE); .getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
nm.cancel(NOTIFICATION_TAG, 0); nm.cancel(OCSMSNotificationUI.NOTIFICATION_TAG, 0);
} else { } else {
nm.cancel(NOTIFICATION_TAG.hashCode()); nm.cancel(OCSMSNotificationUI.NOTIFICATION_TAG.hashCode());
} }
} }
} }

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
* Copyright (c) 2014-2015, Loic Blot <loic.blot@unix-experience.fr>
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="fr.unix_experience.owncloud_sms.activities.remote_account.AccountActionsActivity"
android:orientation="vertical">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/list"
android:choiceMode="singleChoice"
android:drawSelectorOnTop="true"/>
</LinearLayout>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
* Copyright (c) 2014-2015, Loic Blot <loic.blot@unix-experience.fr>
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="fr.unix_experience.owncloud_sms.activities.remote_account.RestoreMessagesActivity">
</RelativeLayout>

View File

@ -168,5 +168,7 @@
<string name="err_cannot_read_contacts">We cannot read your contacts.</string> <string name="err_cannot_read_contacts">We cannot read your contacts.</string>
<string name="err_cannot_read_sms">We cannot read your SMS.</string> <string name="err_cannot_read_sms">We cannot read your SMS.</string>
<string name="action_appinfo_perms">App Infos and permissions</string> <string name="action_appinfo_perms">App Infos and permissions</string>
<string name="restore_all_messages">Restore all messages</string>
<string name="account_actions">Account actions</string>
</resources> </resources>

View File

@ -153,4 +153,6 @@
<string name="err_cannot_read_contacts">Nous ne pouvons lire vos contacts.</string> <string name="err_cannot_read_contacts">Nous ne pouvons lire vos contacts.</string>
<string name="err_cannot_read_sms">Nous ne pouvons pas lire vos SMS.</string> <string name="err_cannot_read_sms">Nous ne pouvons pas lire vos SMS.</string>
<string name="action_appinfo_perms">Infos et permissions</string> <string name="action_appinfo_perms">Infos et permissions</string>
<string name="restore_all_messages">Restaurer tous les messages</string>
<string name="account_actions">Actions du compte</string>
</resources> </resources>

View File

@ -27,7 +27,7 @@
--> -->
<resources> <resources>
<!-- Translation version, reference for translators --> <!-- Translation version, reference for translators -->
<string name="gp_translation_version">3</string> <string name="gp_translation_version" translatable="false">3</string>
<!-- Translations must begin here --> <!-- Translations must begin here -->
<string name="gp_short_description">ownCloud SMS synchronize your local SMS on your ownCloud instance</string> <string name="gp_short_description">ownCloud SMS synchronize your local SMS on your ownCloud instance</string>

View File

@ -41,7 +41,7 @@
<string name="login_logo">Login logo</string> <string name="login_logo">Login logo</string>
<!-- System strings: preferences --> <!-- System strings: preferences -->
<string name="shared_preference_file">ownCloudSMSPrefs</string> <string name="shared_preference_file" translatable="false">ownCloudSMSPrefs</string>
<string name="pref_lastmsgdate">last_message_date</string> <string name="pref_lastmsgdate">last_message_date</string>
<!-- Translations must begin there --> <!-- Translations must begin there -->
@ -203,4 +203,6 @@
<string name="err_cannot_read_contacts">We cannot read your contacts.</string> <string name="err_cannot_read_contacts">We cannot read your contacts.</string>
<string name="err_cannot_read_sms">We cannot read your SMS.</string> <string name="err_cannot_read_sms">We cannot read your SMS.</string>
<string name="action_appinfo_perms">App Infos and permissions</string> <string name="action_appinfo_perms">App Infos and permissions</string>
<string name="restore_all_messages">Restore all messages</string>
<string name="account_actions">Account actions</string>
</resources> </resources>