| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright 2016 Christian Basler
 | 
					
						
							|  |  |  |  *
 | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License");
 | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License.
 | 
					
						
							|  |  |  |  * You may obtain a copy of the License at
 | 
					
						
							|  |  |  |  *
 | 
					
						
							|  |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  *
 | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software
 | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS,
 | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and
 | 
					
						
							|  |  |  |  * limitations under the License.
 | 
					
						
							|  |  |  |  */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | package ch.dissem.apps.abit;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-27 20:04:17 +01:00
										 |  |  | import android.app.AlertDialog;
 | 
					
						
							| 
									
										
										
										
											2015-10-23 22:40:09 +02:00
										 |  |  | import android.content.ComponentName;
 | 
					
						
							|  |  |  | import android.content.Context;
 | 
					
						
							| 
									
										
										
										
											2015-12-27 20:04:17 +01:00
										 |  |  | import android.content.DialogInterface;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | import android.content.Intent;
 | 
					
						
							| 
									
										
										
										
											2015-10-23 22:40:09 +02:00
										 |  |  | import android.content.ServiceConnection;
 | 
					
						
							| 
									
										
										
										
											2016-02-12 00:19:15 +01:00
										 |  |  | import android.graphics.Point;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | import android.os.Bundle;
 | 
					
						
							| 
									
										
										
										
											2015-10-23 22:40:09 +02:00
										 |  |  | import android.os.IBinder;
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  | import android.support.v4.app.Fragment;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | import android.support.v7.app.AppCompatActivity;
 | 
					
						
							|  |  |  | import android.support.v7.widget.Toolbar;
 | 
					
						
							|  |  |  | import android.view.View;
 | 
					
						
							| 
									
										
										
										
											2016-02-12 00:19:15 +01:00
										 |  |  | import android.view.ViewGroup;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | import android.widget.AdapterView;
 | 
					
						
							| 
									
										
										
										
											2015-10-12 14:44:01 +02:00
										 |  |  | import android.widget.CompoundButton;
 | 
					
						
							| 
									
										
										
										
											2016-02-12 00:19:15 +01:00
										 |  |  | import android.widget.RelativeLayout;
 | 
					
						
							| 
									
										
										
										
											2015-10-06 12:51:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-12 00:19:15 +01:00
										 |  |  | import com.github.amlcurran.showcaseview.ShowcaseView;
 | 
					
						
							|  |  |  | import com.github.amlcurran.showcaseview.targets.Target;
 | 
					
						
							| 
									
										
										
										
											2015-08-14 17:25:05 +02:00
										 |  |  | import com.mikepenz.community_material_typeface_library.CommunityMaterial;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | import com.mikepenz.google_material_typeface_library.GoogleMaterial;
 | 
					
						
							|  |  |  | import com.mikepenz.iconics.IconicsDrawable;
 | 
					
						
							|  |  |  | import com.mikepenz.materialdrawer.Drawer;
 | 
					
						
							|  |  |  | import com.mikepenz.materialdrawer.DrawerBuilder;
 | 
					
						
							|  |  |  | import com.mikepenz.materialdrawer.accountswitcher.AccountHeader;
 | 
					
						
							|  |  |  | import com.mikepenz.materialdrawer.accountswitcher.AccountHeaderBuilder;
 | 
					
						
							| 
									
										
										
										
											2016-02-12 00:19:15 +01:00
										 |  |  | import com.mikepenz.materialdrawer.model.DividerDrawerItem;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
 | 
					
						
							|  |  |  | import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
 | 
					
						
							|  |  |  | import com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem;
 | 
					
						
							| 
									
										
										
										
											2015-10-12 14:44:01 +02:00
										 |  |  | import com.mikepenz.materialdrawer.model.SwitchDrawerItem;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
 | 
					
						
							|  |  |  | import com.mikepenz.materialdrawer.model.interfaces.IProfile;
 | 
					
						
							|  |  |  | import com.mikepenz.materialdrawer.model.interfaces.Nameable;
 | 
					
						
							| 
									
										
										
										
											2015-10-12 14:44:01 +02:00
										 |  |  | import com.mikepenz.materialdrawer.model.interfaces.OnCheckedChangeListener;
 | 
					
						
							| 
									
										
										
										
											2015-10-06 12:51:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-28 13:49:53 +02:00
										 |  |  | import org.slf4j.Logger;
 | 
					
						
							|  |  |  | import org.slf4j.LoggerFactory;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  | import java.io.Serializable;
 | 
					
						
							| 
									
										
										
										
											2016-02-23 07:06:34 +01:00
										 |  |  | import java.lang.ref.WeakReference;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | import java.util.ArrayList;
 | 
					
						
							| 
									
										
										
										
											2015-11-22 12:28:31 +01:00
										 |  |  | import java.util.Collection;
 | 
					
						
							|  |  |  | import java.util.List;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-18 21:47:07 +02:00
										 |  |  | import ch.dissem.apps.abit.listener.ActionBarListener;
 | 
					
						
							|  |  |  | import ch.dissem.apps.abit.listener.ListSelectionListener;
 | 
					
						
							| 
									
										
										
										
											2015-10-31 07:49:03 +01:00
										 |  |  | import ch.dissem.apps.abit.service.BitmessageService;
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  | import ch.dissem.apps.abit.service.BitmessageService.BitmessageBinder;
 | 
					
						
							| 
									
										
										
										
											2015-10-12 14:44:01 +02:00
										 |  |  | import ch.dissem.apps.abit.service.Singleton;
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  | import ch.dissem.apps.abit.synchronization.SyncAdapter;
 | 
					
						
							|  |  |  | import ch.dissem.apps.abit.util.Preferences;
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  | import ch.dissem.bitmessage.BitmessageContext;
 | 
					
						
							| 
									
										
										
										
											2015-10-12 14:44:01 +02:00
										 |  |  | import ch.dissem.bitmessage.entity.BitmessageAddress;
 | 
					
						
							|  |  |  | import ch.dissem.bitmessage.entity.Plaintext;
 | 
					
						
							|  |  |  | import ch.dissem.bitmessage.entity.valueobject.Label;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  | import static ch.dissem.apps.abit.service.BitmessageService.isRunning;
 | 
					
						
							| 
									
										
										
										
											2015-10-12 14:44:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * An activity representing a list of Messages. This activity
 | 
					
						
							|  |  |  |  * has different presentations for handset and tablet-size devices. On
 | 
					
						
							|  |  |  |  * handsets, the activity presents a list of items, which when touched,
 | 
					
						
							|  |  |  |  * lead to a {@link MessageDetailActivity} representing
 | 
					
						
							|  |  |  |  * item details. On tablets, the activity presents the list of items and
 | 
					
						
							|  |  |  |  * item details side-by-side using two vertical panes.
 | 
					
						
							|  |  |  |  * <p>
 | 
					
						
							|  |  |  |  * The activity makes heavy use of fragments. The list of items is a
 | 
					
						
							|  |  |  |  * {@link MessageListFragment} and the item details
 | 
					
						
							|  |  |  |  * (if present) is a {@link MessageDetailFragment}.
 | 
					
						
							|  |  |  |  * </p><p>
 | 
					
						
							|  |  |  |  * This activity also implements the required
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |  * {@link ListSelectionListener} interface | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |  * to listen for item selections.
 | 
					
						
							|  |  |  |  * </p>
 | 
					
						
							|  |  |  |  */
 | 
					
						
							| 
									
										
										
										
											2015-11-22 12:28:31 +01:00
										 |  |  | public class MainActivity extends AppCompatActivity
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |         implements ListSelectionListener<Serializable>, ActionBarListener {
 | 
					
						
							| 
									
										
										
										
											2015-09-04 08:19:07 +02:00
										 |  |  |     public static final String EXTRA_SHOW_MESSAGE = "ch.dissem.abit.ShowMessage";
 | 
					
						
							|  |  |  |     public static final String ACTION_SHOW_INBOX = "ch.dissem.abit.ShowInbox";
 | 
					
						
							| 
									
										
										
										
											2015-08-28 13:49:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-22 12:28:31 +01:00
										 |  |  |     private static final Logger LOG = LoggerFactory.getLogger(MainActivity.class);
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |     private static final int ADD_IDENTITY = 1;
 | 
					
						
							| 
									
										
										
										
											2016-01-29 18:05:43 +01:00
										 |  |  |     private static final int MANAGE_IDENTITY = 2;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-23 07:06:34 +01:00
										 |  |  |     public static WeakReference<MainActivity> instance;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |     /**
 | 
					
						
							|  |  |  |      * Whether or not the activity is in two-pane mode, i.e. running on a tablet
 | 
					
						
							|  |  |  |      * device.
 | 
					
						
							|  |  |  |      */
 | 
					
						
							|  |  |  |     private boolean twoPane;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  |     private static BitmessageBinder service;
 | 
					
						
							| 
									
										
										
										
											2015-10-31 07:49:03 +01:00
										 |  |  |     private static boolean bound;
 | 
					
						
							|  |  |  |     private static ServiceConnection connection = new ServiceConnection() {
 | 
					
						
							| 
									
										
										
										
											2015-10-23 22:40:09 +02:00
										 |  |  |         @Override
 | 
					
						
							|  |  |  |         public void onServiceConnected(ComponentName name, IBinder service) {
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  |             MainActivity.service = (BitmessageBinder) service;
 | 
					
						
							| 
									
										
										
										
											2015-11-22 12:28:31 +01:00
										 |  |  |             MainActivity.bound = true;
 | 
					
						
							| 
									
										
										
										
											2015-10-23 22:40:09 +02:00
										 |  |  |         }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         @Override
 | 
					
						
							|  |  |  |         public void onServiceDisconnected(ComponentName name) {
 | 
					
						
							|  |  |  |             service = null;
 | 
					
						
							|  |  |  |             bound = false;
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  |     };
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |     private Label selectedLabel;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  |     private BitmessageContext bmc;
 | 
					
						
							|  |  |  |     private AccountHeader accountHeader;
 | 
					
						
							| 
									
										
										
										
											2015-10-23 22:40:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-12 00:19:15 +01:00
										 |  |  |     private Drawer drawer;
 | 
					
						
							|  |  |  |     private ShowcaseView showcaseView;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |     @Override
 | 
					
						
							|  |  |  |     protected void onCreate(Bundle savedInstanceState) {
 | 
					
						
							|  |  |  |         super.onCreate(savedInstanceState);
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  |         bmc = Singleton.getBitmessageContext(this);
 | 
					
						
							|  |  |  |         List<Label> labels = bmc.messages().getLabels();
 | 
					
						
							| 
									
										
										
										
											2015-11-22 12:28:31 +01:00
										 |  |  |         if (selectedLabel == null) {
 | 
					
						
							|  |  |  |             selectedLabel = labels.get(0);
 | 
					
						
							|  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         setContentView(R.layout.activity_message_list);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 17:25:05 +02:00
										 |  |  |         final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |         setSupportActionBar(toolbar);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |         MessageListFragment listFragment = new MessageListFragment();
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  |         getSupportFragmentManager().beginTransaction().replace(R.id.item_list, listFragment)
 | 
					
						
							|  |  |  |                 .commit();
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |         if (findViewById(R.id.message_detail_container) != null) {
 | 
					
						
							|  |  |  |             // The detail container view will be present only in the
 | 
					
						
							|  |  |  |             // large-screen layouts (res/values-large and
 | 
					
						
							|  |  |  |             // res/values-sw600dp). If this view is present, then the
 | 
					
						
							|  |  |  |             // activity should be in two-pane mode.
 | 
					
						
							|  |  |  |             twoPane = true;
 | 
					
						
							| 
									
										
										
										
											2015-10-08 14:11:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // In two-pane mode, list items should be given the
 | 
					
						
							|  |  |  |             // 'activated' state when touched.
 | 
					
						
							|  |  |  |             listFragment.setActivateOnItemClick(true);
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |         }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-22 12:28:31 +01:00
										 |  |  |         createDrawer(toolbar, labels);
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 08:19:07 +02:00
										 |  |  |         Singleton.getMessageListener(this).resetNotification();
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // handle intents
 | 
					
						
							|  |  |  |         if (getIntent().hasExtra(EXTRA_SHOW_MESSAGE)) {
 | 
					
						
							| 
									
										
										
										
											2015-10-06 12:51:09 +02:00
										 |  |  |             onItemSelected(getIntent().getSerializableExtra(EXTRA_SHOW_MESSAGE));
 | 
					
						
							|  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2015-10-08 14:11:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  |         if (Preferences.useTrustedNode(this)) {
 | 
					
						
							|  |  |  |             SyncAdapter.startSync(this);
 | 
					
						
							|  |  |  |         } else {
 | 
					
						
							|  |  |  |             SyncAdapter.stopSync(this);
 | 
					
						
							| 
									
										
										
										
											2015-10-08 14:11:45 +02:00
										 |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2016-02-12 00:19:15 +01:00
										 |  |  |         if (drawer.isDrawerOpen()) {
 | 
					
						
							|  |  |  |             RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(ViewGroup
 | 
					
						
							|  |  |  |                     .LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
 | 
					
						
							|  |  |  |             lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
 | 
					
						
							|  |  |  |             lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 | 
					
						
							|  |  |  |             int margin = ((Number) (getResources().getDisplayMetrics().density * 12)).intValue();
 | 
					
						
							|  |  |  |             lps.setMargins(margin, margin, margin, margin);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             showcaseView = new ShowcaseView.Builder(this)
 | 
					
						
							|  |  |  |                     .withMaterialShowcase()
 | 
					
						
							|  |  |  |                     .setStyle(R.style.CustomShowcaseTheme)
 | 
					
						
							|  |  |  |                     .setContentTitle(R.string.full_node)
 | 
					
						
							|  |  |  |                     .setContentText(R.string.full_node_description)
 | 
					
						
							|  |  |  |                     .setTarget(new Target() {
 | 
					
						
							|  |  |  |                                    @Override
 | 
					
						
							|  |  |  |                                    public Point getPoint() {
 | 
					
						
							|  |  |  |                                        View view = drawer.getStickyFooter();
 | 
					
						
							|  |  |  |                                        int[] location = new int[2];
 | 
					
						
							|  |  |  |                                        view.getLocationInWindow(location);
 | 
					
						
							|  |  |  |                                        int x = location[0] + 7 * view.getWidth() / 8;
 | 
					
						
							|  |  |  |                                        int y = location[1] + view.getHeight() / 2;
 | 
					
						
							|  |  |  |                                        return new Point(x, y);
 | 
					
						
							|  |  |  |                                    }
 | 
					
						
							|  |  |  |                                }
 | 
					
						
							|  |  |  |                     )
 | 
					
						
							|  |  |  |                     .replaceEndButton(R.layout.showcase_button)
 | 
					
						
							|  |  |  |                     .hideOnTouchOutside()
 | 
					
						
							|  |  |  |                     .build();
 | 
					
						
							|  |  |  |             showcaseView.setButtonPosition(lps);
 | 
					
						
							|  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |     private void changeList(AbstractItemListFragment<?> listFragment) {
 | 
					
						
							|  |  |  |         getSupportFragmentManager()
 | 
					
						
							|  |  |  |                 .beginTransaction()
 | 
					
						
							|  |  |  |                 .replace(R.id.item_list, listFragment)
 | 
					
						
							|  |  |  |                 .addToBackStack(null)
 | 
					
						
							|  |  |  |                 .commit();
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (twoPane) {
 | 
					
						
							|  |  |  |             // In two-pane mode, list items should be given the
 | 
					
						
							|  |  |  |             // 'activated' state when touched.
 | 
					
						
							|  |  |  |             listFragment.setActivateOnItemClick(true);
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-22 12:28:31 +01:00
										 |  |  |     private void createDrawer(Toolbar toolbar, Collection<Label> labels) {
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |         final ArrayList<IProfile> profiles = new ArrayList<>();
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  |         for (BitmessageAddress identity : bmc.addresses().getIdentities()) {
 | 
					
						
							| 
									
										
										
										
											2015-08-28 13:49:53 +02:00
										 |  |  |             LOG.info("Adding identity " + identity.getAddress());
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |             profiles.add(new ProfileDrawerItem()
 | 
					
						
							| 
									
										
										
										
											2015-09-04 08:19:07 +02:00
										 |  |  |                             .withIcon(new Identicon(identity))
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |                             .withName(identity.toString())
 | 
					
						
							| 
									
										
										
										
											2016-01-29 18:05:43 +01:00
										 |  |  |                             .withNameShown(true)
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |                             .withEmail(identity.getAddress())
 | 
					
						
							|  |  |  |                             .withTag(identity)
 | 
					
						
							|  |  |  |             );
 | 
					
						
							|  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  |         if (profiles.isEmpty()) {
 | 
					
						
							| 
									
										
										
										
											2016-01-19 07:43:48 +01:00
										 |  |  |             // Create an initial identity
 | 
					
						
							|  |  |  |             BitmessageAddress identity = Singleton.getIdentity(this);
 | 
					
						
							|  |  |  |             profiles.add(new ProfileDrawerItem()
 | 
					
						
							|  |  |  |                             .withIcon(new Identicon(identity))
 | 
					
						
							|  |  |  |                             .withName(identity.toString())
 | 
					
						
							|  |  |  |                             .withEmail(identity.getAddress())
 | 
					
						
							|  |  |  |                             .withTag(identity)
 | 
					
						
							|  |  |  |             );
 | 
					
						
							|  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |         profiles.add(new ProfileSettingDrawerItem()
 | 
					
						
							|  |  |  |                         .withName("Add Identity")
 | 
					
						
							|  |  |  |                         .withDescription("Create new identity")
 | 
					
						
							|  |  |  |                         .withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_add)
 | 
					
						
							|  |  |  |                                 .actionBar()
 | 
					
						
							|  |  |  |                                 .paddingDp(5)
 | 
					
						
							|  |  |  |                                 .colorRes(R.color.icons))
 | 
					
						
							|  |  |  |                         .withIdentifier(ADD_IDENTITY)
 | 
					
						
							|  |  |  |         );
 | 
					
						
							|  |  |  |         profiles.add(new ProfileSettingDrawerItem()
 | 
					
						
							| 
									
										
										
										
											2015-08-14 17:25:05 +02:00
										 |  |  |                         .withName(getString(R.string.manage_identity))
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |                         .withIcon(GoogleMaterial.Icon.gmd_settings)
 | 
					
						
							| 
									
										
										
										
											2016-01-29 18:05:43 +01:00
										 |  |  |                         .withIdentifier(MANAGE_IDENTITY)
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |         );
 | 
					
						
							|  |  |  |         // Create the AccountHeader
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  |         accountHeader = new AccountHeaderBuilder()
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |                 .withActivity(this)
 | 
					
						
							|  |  |  |                 .withHeaderBackground(R.drawable.header)
 | 
					
						
							|  |  |  |                 .withProfiles(profiles)
 | 
					
						
							|  |  |  |                 .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
 | 
					
						
							|  |  |  |                     @Override
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  |                     public boolean onProfileChanged(View view, IProfile profile, boolean
 | 
					
						
							|  |  |  |                             currentProfile) {
 | 
					
						
							| 
									
										
										
										
											2016-01-29 18:05:43 +01:00
										 |  |  |                         switch (profile.getIdentifier()) {
 | 
					
						
							|  |  |  |                             case ADD_IDENTITY:
 | 
					
						
							|  |  |  |                                 new AlertDialog.Builder(MainActivity.this)
 | 
					
						
							|  |  |  |                                         .setMessage(R.string.add_identity_warning)
 | 
					
						
							|  |  |  |                                         .setPositiveButton(android.R.string.yes, new
 | 
					
						
							|  |  |  |                                                 DialogInterface.OnClickListener() {
 | 
					
						
							| 
									
										
										
										
											2016-02-12 00:19:15 +01:00
										 |  |  |                                                     @Override
 | 
					
						
							|  |  |  |                                                     public void onClick(DialogInterface dialog,
 | 
					
						
							|  |  |  |                                                                         int which) {
 | 
					
						
							|  |  |  |                                                         BitmessageAddress identity = bmc
 | 
					
						
							|  |  |  |                                                                 .createIdentity(false);
 | 
					
						
							|  |  |  |                                                         IProfile newProfile = new
 | 
					
						
							|  |  |  |                                                                 ProfileDrawerItem()
 | 
					
						
							|  |  |  |                                                                 .withName(identity.toString())
 | 
					
						
							|  |  |  |                                                                 .withEmail(identity.getAddress())
 | 
					
						
							|  |  |  |                                                                 .withTag(identity);
 | 
					
						
							|  |  |  |                                                         if (accountHeader.getProfiles() != null) {
 | 
					
						
							|  |  |  |                                                             // we know that there are 2 setting
 | 
					
						
							|  |  |  |                                                             // elements.
 | 
					
						
							|  |  |  |                                                             // Set the new profile above them ;)
 | 
					
						
							|  |  |  |                                                             accountHeader.addProfile(
 | 
					
						
							|  |  |  |                                                                     newProfile, accountHeader
 | 
					
						
							|  |  |  |                                                                             .getProfiles().size()
 | 
					
						
							|  |  |  |                                                                             - 2);
 | 
					
						
							|  |  |  |                                                         } else {
 | 
					
						
							|  |  |  |                                                             accountHeader.addProfiles(newProfile);
 | 
					
						
							|  |  |  |                                                         }
 | 
					
						
							|  |  |  |                                                     }
 | 
					
						
							|  |  |  |                                                 })
 | 
					
						
							| 
									
										
										
										
											2016-01-29 18:05:43 +01:00
										 |  |  |                                         .setNegativeButton(android.R.string.no, null)
 | 
					
						
							|  |  |  |                                         .show();
 | 
					
						
							|  |  |  |                                 break;
 | 
					
						
							|  |  |  |                             case MANAGE_IDENTITY:
 | 
					
						
							|  |  |  |                                 Intent show = new Intent(MainActivity.this,
 | 
					
						
							|  |  |  |                                         AddressDetailActivity.class);
 | 
					
						
							|  |  |  |                                 show.putExtra(AddressDetailFragment.ARG_ITEM,
 | 
					
						
							|  |  |  |                                         Singleton.getIdentity(getApplicationContext()));
 | 
					
						
							|  |  |  |                                 startActivity(show);
 | 
					
						
							|  |  |  |                                 break;
 | 
					
						
							|  |  |  |                             default:
 | 
					
						
							|  |  |  |                                 if (profile instanceof ProfileDrawerItem) {
 | 
					
						
							|  |  |  |                                     Object tag = ((ProfileDrawerItem) profile).getTag();
 | 
					
						
							|  |  |  |                                     if (tag instanceof BitmessageAddress) {
 | 
					
						
							|  |  |  |                                         Singleton.setIdentity((BitmessageAddress) tag);
 | 
					
						
							|  |  |  |                                     }
 | 
					
						
							|  |  |  |                                 }
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |                         }
 | 
					
						
							|  |  |  |                         // false if it should close the drawer
 | 
					
						
							|  |  |  |                         return false;
 | 
					
						
							|  |  |  |                     }
 | 
					
						
							|  |  |  |                 })
 | 
					
						
							|  |  |  |                 .build();
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  |         if (profiles.size() > 2) { // There's always the add and manage identity items
 | 
					
						
							| 
									
										
										
										
											2015-11-11 21:03:03 +01:00
										 |  |  |             accountHeader.setActiveProfile(profiles.get(0), true);
 | 
					
						
							|  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         ArrayList<IDrawerItem> drawerItems = new ArrayList<>();
 | 
					
						
							| 
									
										
										
										
											2015-11-22 12:28:31 +01:00
										 |  |  |         for (Label label : labels) {
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  |             PrimaryDrawerItem item = new PrimaryDrawerItem().withName(label.toString()).withTag
 | 
					
						
							|  |  |  |                     (label);
 | 
					
						
							| 
									
										
										
										
											2015-11-11 21:03:03 +01:00
										 |  |  |             if (label.getType() == null) {
 | 
					
						
							|  |  |  |                 item.withIcon(CommunityMaterial.Icon.cmd_label);
 | 
					
						
							|  |  |  |             } else {
 | 
					
						
							|  |  |  |                 switch (label.getType()) {
 | 
					
						
							|  |  |  |                     case INBOX:
 | 
					
						
							|  |  |  |                         item.withIcon(GoogleMaterial.Icon.gmd_inbox);
 | 
					
						
							|  |  |  |                         break;
 | 
					
						
							|  |  |  |                     case DRAFT:
 | 
					
						
							|  |  |  |                         item.withIcon(CommunityMaterial.Icon.cmd_file);
 | 
					
						
							|  |  |  |                         break;
 | 
					
						
							|  |  |  |                     case SENT:
 | 
					
						
							|  |  |  |                         item.withIcon(CommunityMaterial.Icon.cmd_send);
 | 
					
						
							|  |  |  |                         break;
 | 
					
						
							|  |  |  |                     case BROADCAST:
 | 
					
						
							|  |  |  |                         item.withIcon(CommunityMaterial.Icon.cmd_rss);
 | 
					
						
							|  |  |  |                         break;
 | 
					
						
							|  |  |  |                     case UNREAD:
 | 
					
						
							|  |  |  |                         item.withIcon(GoogleMaterial.Icon.gmd_markunread_mailbox);
 | 
					
						
							|  |  |  |                         break;
 | 
					
						
							|  |  |  |                     case TRASH:
 | 
					
						
							|  |  |  |                         item.withIcon(GoogleMaterial.Icon.gmd_delete);
 | 
					
						
							|  |  |  |                         break;
 | 
					
						
							|  |  |  |                     default:
 | 
					
						
							|  |  |  |                         item.withIcon(CommunityMaterial.Icon.cmd_label);
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							| 
									
										
										
										
											2015-09-06 17:45:21 +02:00
										 |  |  |             }
 | 
					
						
							|  |  |  |             drawerItems.add(item);
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2015-10-12 16:00:43 +02:00
										 |  |  |         drawerItems.add(new PrimaryDrawerItem()
 | 
					
						
							|  |  |  |                         .withName(R.string.archive)
 | 
					
						
							|  |  |  |                         .withTag(null)
 | 
					
						
							|  |  |  |                         .withIcon(CommunityMaterial.Icon.cmd_archive)
 | 
					
						
							|  |  |  |         );
 | 
					
						
							| 
									
										
										
										
											2016-02-12 00:19:15 +01:00
										 |  |  |         drawerItems.add(new DividerDrawerItem());
 | 
					
						
							|  |  |  |         drawerItems.add(new PrimaryDrawerItem()
 | 
					
						
							|  |  |  |                 .withName(R.string.contacts_and_subscriptions)
 | 
					
						
							|  |  |  |                 .withIcon(GoogleMaterial.Icon.gmd_contacts));
 | 
					
						
							|  |  |  |         drawerItems.add(new PrimaryDrawerItem()
 | 
					
						
							|  |  |  |                 .withName(R.string.settings)
 | 
					
						
							|  |  |  |                 .withIcon(GoogleMaterial.Icon.gmd_settings));
 | 
					
						
							| 
									
										
										
										
											2015-10-12 16:00:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-12 00:19:15 +01:00
										 |  |  |         drawer = new DrawerBuilder()
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |                 .withActivity(this)
 | 
					
						
							|  |  |  |                 .withToolbar(toolbar)
 | 
					
						
							|  |  |  |                 .withAccountHeader(accountHeader)
 | 
					
						
							|  |  |  |                 .withDrawerItems(drawerItems)
 | 
					
						
							|  |  |  |                 .addStickyDrawerItems(
 | 
					
						
							| 
									
										
										
										
											2015-10-12 14:44:01 +02:00
										 |  |  |                         new SwitchDrawerItem()
 | 
					
						
							|  |  |  |                                 .withName(R.string.full_node)
 | 
					
						
							|  |  |  |                                 .withIcon(CommunityMaterial.Icon.cmd_cloud_outline)
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  |                                 .withChecked(isRunning())
 | 
					
						
							| 
									
										
										
										
											2015-10-12 14:44:01 +02:00
										 |  |  |                                 .withOnCheckedChangeListener(new OnCheckedChangeListener() {
 | 
					
						
							|  |  |  |                                     @Override
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  |                                     public void onCheckedChanged(IDrawerItem drawerItem,
 | 
					
						
							|  |  |  |                                                                  CompoundButton buttonView,
 | 
					
						
							|  |  |  |                                                                  boolean isChecked) {
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  |                                         if (isChecked) {
 | 
					
						
							|  |  |  |                                             checkAndStartNode(buttonView);
 | 
					
						
							|  |  |  |                                         } else {
 | 
					
						
							|  |  |  |                                             service.shutdownNode();
 | 
					
						
							| 
									
										
										
										
											2015-10-21 16:43:13 +02:00
										 |  |  |                                         }
 | 
					
						
							| 
									
										
										
										
											2015-10-12 14:44:01 +02:00
										 |  |  |                                     }
 | 
					
						
							|  |  |  |                                 })
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |                 )
 | 
					
						
							|  |  |  |                 .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
 | 
					
						
							|  |  |  |                     @Override
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  |                     public boolean onItemClick(AdapterView<?> adapterView, View view, int i, long
 | 
					
						
							|  |  |  |                             l, IDrawerItem item) {
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |                         if (item.getTag() instanceof Label) {
 | 
					
						
							|  |  |  |                             selectedLabel = (Label) item.getTag();
 | 
					
						
							| 
									
										
										
										
											2015-10-18 21:47:07 +02:00
										 |  |  |                             showSelectedLabel();
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |                             return false;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |                         } else if (item instanceof Nameable<?>) {
 | 
					
						
							|  |  |  |                             Nameable<?> ni = (Nameable<?>) item;
 | 
					
						
							|  |  |  |                             switch (ni.getNameRes()) {
 | 
					
						
							| 
									
										
										
										
											2015-11-11 21:03:03 +01:00
										 |  |  |                                 case R.string.contacts_and_subscriptions:
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  |                                     if (!(getSupportFragmentManager().findFragmentById(R.id
 | 
					
						
							| 
									
										
										
										
											2016-01-29 18:05:43 +01:00
										 |  |  |                                             .item_list) instanceof AddressListFragment)) {
 | 
					
						
							|  |  |  |                                         changeList(new AddressListFragment());
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |                                     } else {
 | 
					
						
							| 
									
										
										
										
											2016-01-29 18:05:43 +01:00
										 |  |  |                                         ((AddressListFragment) getSupportFragmentManager()
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |                                                 .findFragmentById(R.id.item_list)).updateList();
 | 
					
						
							|  |  |  |                                     }
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 17:25:05 +02:00
										 |  |  |                                     break;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |                                 case R.string.settings:
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  |                                     startActivity(new Intent(MainActivity.this, SettingsActivity
 | 
					
						
							|  |  |  |                                             .class));
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |                                     break;
 | 
					
						
							| 
									
										
										
										
											2015-10-18 21:47:07 +02:00
										 |  |  |                                 case R.string.archive:
 | 
					
						
							|  |  |  |                                     selectedLabel = null;
 | 
					
						
							|  |  |  |                                     showSelectedLabel();
 | 
					
						
							|  |  |  |                                     break;
 | 
					
						
							| 
									
										
										
										
											2015-10-12 14:44:01 +02:00
										 |  |  |                                 case R.string.full_node:
 | 
					
						
							|  |  |  |                                     return true;
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |                             }
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                         return false;
 | 
					
						
							|  |  |  |                     }
 | 
					
						
							|  |  |  |                 })
 | 
					
						
							| 
									
										
										
										
											2016-02-12 00:19:15 +01:00
										 |  |  |                 .withShowDrawerOnFirstLaunch(true)
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |                 .build();
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-23 07:06:34 +01:00
										 |  |  |     @Override
 | 
					
						
							|  |  |  |     protected void onResume() {
 | 
					
						
							|  |  |  |         instance = new WeakReference<>(this);
 | 
					
						
							|  |  |  |         updateUnread();
 | 
					
						
							|  |  |  |         super.onResume();
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @Override
 | 
					
						
							|  |  |  |     protected void onPause() {
 | 
					
						
							|  |  |  |         super.onPause();
 | 
					
						
							|  |  |  |         instance = null;
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-27 20:04:17 +01:00
										 |  |  |     private void checkAndStartNode(final CompoundButton buttonView) {
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  |         if (service == null) return;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-27 20:04:17 +01:00
										 |  |  |         if (Preferences.isConnectionAllowed(MainActivity.this)) {
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  |             service.startupNode();
 | 
					
						
							| 
									
										
										
										
											2015-12-27 20:04:17 +01:00
										 |  |  |         } else {
 | 
					
						
							|  |  |  |             new AlertDialog.Builder(MainActivity.this)
 | 
					
						
							|  |  |  |                     .setMessage(R.string.full_node_warning)
 | 
					
						
							|  |  |  |                     .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
 | 
					
						
							|  |  |  |                         @Override
 | 
					
						
							|  |  |  |                         public void onClick(DialogInterface dialog, int which) {
 | 
					
						
							| 
									
										
										
										
											2016-01-19 20:50:58 +01:00
										 |  |  |                             service.startupNode();
 | 
					
						
							| 
									
										
										
										
											2015-12-27 20:04:17 +01:00
										 |  |  |                         }
 | 
					
						
							|  |  |  |                     })
 | 
					
						
							|  |  |  |                     .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
 | 
					
						
							|  |  |  |                         @Override
 | 
					
						
							|  |  |  |                         public void onClick(DialogInterface dialog, int which) {
 | 
					
						
							|  |  |  |                             buttonView.setChecked(false);
 | 
					
						
							|  |  |  |                         }
 | 
					
						
							|  |  |  |                     })
 | 
					
						
							|  |  |  |                     .show();
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-23 07:06:34 +01:00
										 |  |  |     @Override
 | 
					
						
							|  |  |  |     public void updateUnread() {
 | 
					
						
							|  |  |  |         for (IDrawerItem item : drawer.getDrawerItems()) {
 | 
					
						
							|  |  |  |             if (item.getTag() instanceof Label) {
 | 
					
						
							|  |  |  |                 Label label = (Label) item.getTag();
 | 
					
						
							|  |  |  |                 int unread = bmc.messages().countUnread(label);
 | 
					
						
							|  |  |  |                 if (unread > 0) {
 | 
					
						
							|  |  |  |                     ((PrimaryDrawerItem) item).withBadge(String.valueOf(unread));
 | 
					
						
							|  |  |  |                 } else {
 | 
					
						
							|  |  |  |                     ((PrimaryDrawerItem) item).withBadge(null);
 | 
					
						
							|  |  |  |                 }
 | 
					
						
							|  |  |  |             }
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-18 21:47:07 +02:00
										 |  |  |     private void showSelectedLabel() {
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  |         if (getSupportFragmentManager().findFragmentById(R.id.item_list) instanceof
 | 
					
						
							|  |  |  |                 MessageListFragment) {
 | 
					
						
							| 
									
										
										
										
											2015-10-18 21:47:07 +02:00
										 |  |  |             ((MessageListFragment) getSupportFragmentManager()
 | 
					
						
							|  |  |  |                     .findFragmentById(R.id.item_list)).updateList(selectedLabel);
 | 
					
						
							|  |  |  |         } else {
 | 
					
						
							| 
									
										
										
										
											2015-10-23 22:40:09 +02:00
										 |  |  |             MessageListFragment listFragment = new MessageListFragment();
 | 
					
						
							| 
									
										
										
										
											2015-10-18 21:47:07 +02:00
										 |  |  |             changeList(listFragment);
 | 
					
						
							|  |  |  |             listFragment.updateList(selectedLabel);
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |     /**
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |      * Callback method from {@link ListSelectionListener}
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |      * indicating that the item with the given ID was selected.
 | 
					
						
							|  |  |  |      */
 | 
					
						
							|  |  |  |     @Override
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |     public void onItemSelected(Serializable item) {
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |         if (twoPane) {
 | 
					
						
							|  |  |  |             // In two-pane mode, show the detail view in this activity by
 | 
					
						
							|  |  |  |             // adding or replacing the detail fragment using a
 | 
					
						
							|  |  |  |             // fragment transaction.
 | 
					
						
							|  |  |  |             Bundle arguments = new Bundle();
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |             arguments.putSerializable(MessageDetailFragment.ARG_ITEM, item);
 | 
					
						
							|  |  |  |             Fragment fragment;
 | 
					
						
							|  |  |  |             if (item instanceof Plaintext)
 | 
					
						
							|  |  |  |                 fragment = new MessageDetailFragment();
 | 
					
						
							|  |  |  |             else if (item instanceof BitmessageAddress)
 | 
					
						
							| 
									
										
										
										
											2016-01-29 18:05:43 +01:00
										 |  |  |                 fragment = new AddressDetailFragment();
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |             else
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  |                 throw new IllegalArgumentException("Plaintext or BitmessageAddress expected, but " +
 | 
					
						
							|  |  |  |                         "was "
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |                         + item.getClass().getSimpleName());
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |             fragment.setArguments(arguments);
 | 
					
						
							|  |  |  |             getSupportFragmentManager().beginTransaction()
 | 
					
						
							|  |  |  |                     .replace(R.id.message_detail_container, fragment)
 | 
					
						
							|  |  |  |                     .commit();
 | 
					
						
							|  |  |  |         } else {
 | 
					
						
							|  |  |  |             // In single-pane mode, simply start the detail activity
 | 
					
						
							|  |  |  |             // for the selected item ID.
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |             Intent detailIntent;
 | 
					
						
							|  |  |  |             if (item instanceof Plaintext)
 | 
					
						
							|  |  |  |                 detailIntent = new Intent(this, MessageDetailActivity.class);
 | 
					
						
							|  |  |  |             else if (item instanceof BitmessageAddress)
 | 
					
						
							| 
									
										
										
										
											2016-01-29 18:05:43 +01:00
										 |  |  |                 detailIntent = new Intent(this, AddressDetailActivity.class);
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |             else
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  |                 throw new IllegalArgumentException("Plaintext or BitmessageAddress expected, but " +
 | 
					
						
							|  |  |  |                         "was "
 | 
					
						
							| 
									
										
										
										
											2015-09-11 07:59:39 +02:00
										 |  |  |                         + item.getClass().getSimpleName());
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             detailIntent.putExtra(MessageDetailFragment.ARG_ITEM, item);
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |             startActivity(detailIntent);
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-06 17:45:21 +02:00
										 |  |  |     @Override
 | 
					
						
							|  |  |  |     public void updateTitle(CharSequence title) {
 | 
					
						
							| 
									
										
										
										
											2016-01-13 17:28:18 +01:00
										 |  |  |         if (getSupportActionBar() != null) {
 | 
					
						
							|  |  |  |             getSupportActionBar().setTitle(title);
 | 
					
						
							|  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2015-09-06 17:45:21 +02:00
										 |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  |     public Label getSelectedLabel() {
 | 
					
						
							|  |  |  |         return selectedLabel;
 | 
					
						
							|  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2015-08-28 13:49:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-23 22:40:09 +02:00
										 |  |  |     @Override
 | 
					
						
							|  |  |  |     protected void onStart() {
 | 
					
						
							|  |  |  |         super.onStart();
 | 
					
						
							| 
									
										
										
										
											2015-12-21 15:31:48 +01:00
										 |  |  |         bindService(new Intent(this, BitmessageService.class), connection, Context
 | 
					
						
							|  |  |  |                 .BIND_AUTO_CREATE);
 | 
					
						
							| 
									
										
										
										
											2015-10-23 22:40:09 +02:00
										 |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @Override
 | 
					
						
							|  |  |  |     protected void onStop() {
 | 
					
						
							|  |  |  |         if (bound) {
 | 
					
						
							|  |  |  |             unbindService(connection);
 | 
					
						
							|  |  |  |             bound = false;
 | 
					
						
							|  |  |  |         }
 | 
					
						
							|  |  |  |         super.onStop();
 | 
					
						
							|  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2016-02-23 07:06:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public static MainActivity getInstance() {
 | 
					
						
							|  |  |  |         if (instance == null) return null;
 | 
					
						
							|  |  |  |         return instance.get();
 | 
					
						
							|  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2015-08-05 19:48:41 +02:00
										 |  |  | }
 |