Skip to content

Commit

Permalink
Move default SMS and system import to "reminders"
Browse files Browse the repository at this point in the history
// FREEBIE
Closes signalapp#1730
  • Loading branch information
mcginty authored and moxie0 committed Jul 27, 2014
1 parent acc7c4c commit 7d68884
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 33 deletions.
Binary file added res/drawable-hdpi/sms_selection_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/sms_system_import_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/sms_selection_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/sms_system_import_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/sms_selection_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/sms_system_import_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/sms_selection_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/sms_system_import_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions res/drawable/light_touch_highlight_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/light_button_highlight" />
<item android:drawable="@color/light_button" />
</selector>
82 changes: 82 additions & 0 deletions res/layout/reminder_header.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/container"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:background="?reminder_header_background">

<ImageView android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/sms_selection_icon"
android:padding="5dp"/>

<LinearLayout android:id="@+id/reminder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="10dp"
android:orientation="vertical">

<TextView android:id="@+id/reminder_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:textColor="@color/white"
android:textSize="18sp"/>

<TextView android:id="@+id/reminder_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textColor="@color/white"
android:textSize="16sp"/>

</LinearLayout>

<LinearLayout android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="right"
android:layout_marginLeft="15dp"
android:orientation="vertical">

<LinearLayout android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top">

<ImageButton android:id="@+id/cancel"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="10dp"
android:background="@drawable/touch_highlight_background"
android:src="@drawable/ic_menu_remove_holo_light"/>
</LinearLayout>

<LinearLayout android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom">

<Button android:id="@+id/ok"
android:layout_width="60sp"
android:layout_height="40sp"
android:gravity="center_vertical|center_horizontal"
android:background="@drawable/light_touch_highlight_background"
android:fontFamily="sans-serif-light"
android:textColor="@color/white"
android:text="@string/yes"
android:padding="2dp"/>

</LinearLayout>

</LinearLayout>

</LinearLayout>
</LinearLayout>
2 changes: 2 additions & 0 deletions res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
<attr name="navigation_drawer_icons" format="reference"/>
<attr name="navigation_drawer_shadow" format="reference"/>

<attr name="reminder_header_background" format="color"/>

<attr name="menu_new_conversation_icon" format="reference" />
<attr name="menu_new_group_icon" format="reference" />
<attr name="menu_search_icon" format="reference" />
Expand Down
3 changes: 2 additions & 1 deletion res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<color name="textsecure_holo_blue_light">#ff33b5e5</color>

<color name="touch_highlight">#400099cc</color>

<color name="light_button">#33ffffff</color>
<color name="light_button_highlight">#66ffffff</color>
<color name="conversation_item_sent_background_dark">#ff284e0a</color>
<color name="conversation_item_sent_background_light">#ff64a926</color>
<color name="conversation_item_sent_shadow_light">#ffd5d5d5</color>
Expand Down
5 changes: 5 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,11 @@
<!-- verify_keys -->
<string name="verify_keys__menu_verified">Verified</string>

<!-- reminder_header -->
<string name="reminder_header_sms_default_title">Use as default SMS app?</string>
<string name="reminder_header_sms_default_text">TextSecure is not currently your default SMS app.</string>
<string name="reminder_header_sms_import_title">Import system SMS?</string>
<string name="reminder_header_sms_import_text">TextSecure can copy your phone\'s SMS messages into its encrypted database.</string>
<!-- EOF -->

</resources>
4 changes: 4 additions & 0 deletions res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
<item name="menu_info_icon">@drawable/ic_dialog_info_holo_light</item>
<item name="menu_forward_icon">@drawable/ic_action_forward_holo_light</item>
<item name="menu_save_icon">@drawable/ic_action_save_holo_light</item>

<item name="reminder_header_background">#ff5a8800</item>
</style>

<style name="TextSecure.LightTheme.NavigationDrawer"
Expand Down Expand Up @@ -160,6 +162,8 @@
<item name="menu_info_icon">@drawable/ic_dialog_info_holo_dark</item>
<item name="menu_forward_icon">@drawable/ic_action_forward_holo_dark</item>
<item name="menu_save_icon">@drawable/ic_action_save_holo_dark</item>

<item name="reminder_header_background">#ff385400</item>
</style>

<style name="TextSecure.DarkTheme.NavigationDrawer"
Expand Down
11 changes: 0 additions & 11 deletions src/org/thoughtcrime/securesms/ConversationListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ public void onResume() {
super.onResume();
dynamicTheme.onResume(this);
dynamicLanguage.onResume(this);

initializeDefaultMessengerCheck();
}

@Override
Expand Down Expand Up @@ -296,15 +294,6 @@ private void initializeResources() {
this.fragment.setMasterSecret(masterSecret);
}

private void initializeDefaultMessengerCheck() {
if (!TextSecurePreferences.hasPromptedDefaultSmsProvider(this) && !Util.isDefaultSmsProvider(this)) {
TextSecurePreferences.setPromptedDefaultSmsProvider(this, true);
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getPackageName());
startActivity(intent);
}
}

class DrawerToggle extends ActionBarDrawerToggle {

public DrawerToggle(Activity activity, DrawerLayout drawerLayout,
Expand Down
128 changes: 124 additions & 4 deletions src/org/thoughtcrime/securesms/ConversationListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,33 @@
*/
package org.thoughtcrime.securesms;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.provider.Telephony;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CursorAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockListFragment;
import com.actionbarsherlock.view.ActionMode;
Expand All @@ -43,9 +55,11 @@
import org.thoughtcrime.securesms.database.loaders.ConversationListLoader;
import org.thoughtcrime.securesms.notifications.MessageNotifier;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.service.ApplicationMigrationService;
import org.thoughtcrime.securesms.util.Dialogs;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.textsecure.crypto.MasterSecret;
import org.whispersystems.textsecure.util.Util;
import org.thoughtcrime.securesms.util.Util;

import java.util.Set;

Expand All @@ -57,25 +71,42 @@ public class ConversationListFragment extends SherlockListFragment
private ConversationSelectedListener listener;
private MasterSecret masterSecret;
private ActionMode actionMode;

private View reminderView;
private String queryFilter = "";

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
return inflater.inflate(R.layout.conversation_list_fragment, container, false);
final View view = inflater.inflate(R.layout.conversation_list_fragment, container, false);
reminderView = LayoutInflater.from(getActivity()).inflate(R.layout.reminder_header, null);
return view;
}

@Override
public void onDestroyView() {
super.onDestroyView();
getListView().setAdapter(null);
}

@Override
public void onActivityCreated(Bundle bundle) {
super.onActivityCreated(bundle);

setHasOptionsMenu(true);
getListView().setAdapter(null);
getListView().addHeaderView(reminderView);
initializeListAdapter();
initializeBatchListener();

getLoaderManager().initLoader(0, null, this);
}

@Override
public void onResume() {
super.onResume();

initializeReminders();
}

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
Expand Down Expand Up @@ -132,7 +163,7 @@ private void setQueryFilter(String query) {
}

public void resetQueryFilter() {
if (!Util.isEmpty(this.queryFilter)) {
if (!TextUtils.isEmpty(this.queryFilter)) {
setQueryFilter("");
}
}
Expand All @@ -147,6 +178,7 @@ public boolean onQueryTextSubmit(String query) {
}
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
return onQueryTextSubmit(newText);
Expand All @@ -170,6 +202,21 @@ public boolean onItemLongClick(AdapterView<?> arg0, View v, int position, long i
});
}

private void initializeReminders() {
final boolean isDefault = Util.isDefaultSmsProvider(getActivity());
if (isDefault) {
TextSecurePreferences.setPromptedDefaultSmsProvider(getActivity(), false);
}

if (!isDefault && !TextSecurePreferences.hasPromptedDefaultSmsProvider(getActivity())) {
showDefaultSmsReminder();
} else if (isDefault && !ApplicationMigrationService.isDatabaseImported(getActivity())) {
showSystemSmsImportReminder();
} else {
reminderView.findViewById(R.id.container).setVisibility(View.GONE);
}
}

private void initializeListAdapter() {
this.setListAdapter(new ConversationListAdapter(getActivity(), null, masterSecret));
getListView().setRecyclerListener((ConversationListAdapter)getListAdapter());
Expand Down Expand Up @@ -292,6 +339,79 @@ public void onDestroyActionMode(ActionMode mode) {
actionMode = null;
}

@TargetApi(VERSION_CODES.KITKAT)
private void showDefaultSmsReminder() {
final ViewGroup container = (ViewGroup) reminderView.findViewById(R.id.container);

setReminderData(R.drawable.sms_selection_icon,
R.string.reminder_header_sms_default_title,
R.string.reminder_header_sms_default_text,
new OnClickListener() {
@Override
public void onClick(View v) {
TextSecurePreferences.setPromptedDefaultSmsProvider(getActivity(), true);
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getActivity().getPackageName());
startActivity(intent);
}
},
new OnClickListener() {
@Override
public void onClick(View v) {
TextSecurePreferences.setPromptedDefaultSmsProvider(getActivity(), true);
container.setVisibility(View.GONE);
}
});
container.setVisibility(View.VISIBLE);
}

private void showSystemSmsImportReminder() {
final ViewGroup container = (ViewGroup) reminderView.findViewById(R.id.container);

setReminderData(R.drawable.sms_system_import_icon,
R.string.reminder_header_sms_import_title,
R.string.reminder_header_sms_import_text,
new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), ApplicationMigrationService.class);
intent.setAction(ApplicationMigrationService.MIGRATE_DATABASE);
intent.putExtra("master_secret", masterSecret);
getActivity().startService(intent);

Intent nextIntent = new Intent(getActivity(), ConversationListActivity.class);
intent.putExtra("master_secret", masterSecret);

Intent activityIntent = new Intent(getActivity(), DatabaseMigrationActivity.class);
activityIntent.putExtra("master_secret", masterSecret);
activityIntent.putExtra("next_intent", nextIntent);
getActivity().startActivity(activityIntent);
}
},
new OnClickListener() {
@Override
public void onClick(View v) {
ApplicationMigrationService.setDatabaseImported(getActivity());
container.setVisibility(View.GONE);
}
});
container.setVisibility(View.VISIBLE);
}

private void setReminderData(int iconResId, int titleResId, int textResId, OnClickListener okListener, OnClickListener cancelListener) {
final ImageButton cancel = (ImageButton) reminderView.findViewById(R.id.cancel);
final Button ok = (Button ) reminderView.findViewById(R.id.ok);
final TextView title = (TextView ) reminderView.findViewById(R.id.reminder_title);
final TextView text = (TextView ) reminderView.findViewById(R.id.reminder_text);
final ImageView icon = (ImageView ) reminderView.findViewById(R.id.icon);

icon.setImageResource(iconResId);
title.setText(titleResId);
text.setText(textResId);
ok.setOnClickListener(okListener);
cancel.setOnClickListener(cancelListener);
}

}


Loading

0 comments on commit 7d68884

Please sign in to comment.