liuzhenxing 3 years ago
parent
commit
a0da0d0b55

+ 1 - 0
.idea/misc.xml

@@ -42,6 +42,7 @@
         <entry key="app/src/main/res/layout/activity_select_face.xml" value="0.1" />
         <entry key="app/src/main/res/layout/item_app.xml" value="0.1" />
         <entry key="app/src/main/res/layout/item_app_title.xml" value="0.1" />
+        <entry key="app/src/main/res/layout/item_contact.xml" value="0.13829787234042554" />
         <entry key="app/src/main/res/layout/layout_appitem.xml" value="0.11018518518518519" />
         <entry key="app/src/main/res/layout/layout_appitem_title.xml" value="0.1" />
         <entry key="app/src/main/res/layout/view_face_0.xml" value="0.1" />

+ 11 - 4
app/src/main/java/com/xplora/xplauncher/adapter/ContactsRecyclerAdapter.java

@@ -20,16 +20,19 @@ import com.xplora.xplauncher.utils.Constant;
 import com.xplora.xplauncher.view.AppItemView;
 import com.xplora.xplauncher.view.RecentItemView;
 
+import java.util.ArrayList;
 import java.util.List;
 
 public class ContactsRecyclerAdapter extends RecyclerView.Adapter<RecentItemView> {
     private Context mContext;
-    private List<RecentModel> mRecentList;
-    private List<ContactModel> mContactsList;
+    private int mViewType = 0;
+    private List<RecentModel> mRecentList = new ArrayList<>();
+    private List<ContactModel> mContactsList = new ArrayList<>();
     private ContactItemOnClickListener mItemOnClickListener;
 
-    public ContactsRecyclerAdapter(Context context, List<RecentModel> recentList, List<ContactModel> contactsList) {
+    public ContactsRecyclerAdapter(Context context, int viewType, List<RecentModel> recentList, List<ContactModel> contactsList) {
         mContext = context;
+        mViewType = viewType;
         mRecentList = recentList;
         mContactsList = contactsList;
     }
@@ -37,7 +40,7 @@ public class ContactsRecyclerAdapter extends RecyclerView.Adapter<RecentItemView
     @NonNull
     @Override
     public RecentItemView onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
-        int layoutId = R.layout.item_recent;
+        int layoutId = mViewType == 0 ? R.layout.item_recent : R.layout.item_contact;
         View view = LayoutInflater.from(viewGroup.getContext()).inflate(layoutId, viewGroup, false);
         RecentItemView holder = new RecentItemView(view);
         return holder;
@@ -79,6 +82,10 @@ public class ContactsRecyclerAdapter extends RecyclerView.Adapter<RecentItemView
         mRecentList = appList;
     }
 
+    public void setViewType(int type) {
+        mViewType = type;
+    }
+
     public void setListOnClickListener(ContactItemOnClickListener listener) {
         this.mItemOnClickListener = listener;
     }

+ 27 - 3
app/src/main/java/com/xplora/xplauncher/view/ContactsPager.java

@@ -1,7 +1,10 @@
 package com.xplora.xplauncher.view;
 
+import android.annotation.SuppressLint;
 import android.content.Context;
 import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.Button;
 
 import androidx.recyclerview.widget.GridLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
@@ -18,22 +21,43 @@ import java.util.List;
 
 
 public class ContactsPager extends BasePager {
-
     private ContactsRecyclerAdapter mRecyclerAdapter;
 
     public ContactsPager(Context context, List<RecentModel> recentList, List<ContactModel> contactsList, ContactsRecyclerAdapter.ContactItemOnClickListener listener) {
         super(context);
 
         mBaseView = LayoutInflater.from(mContext).inflate(R.layout.view_screen_contacts, null);
-
         RecyclerView mRecyclerView = (RecyclerView)mBaseView.findViewById(R.id.recyclerView);
+        Button mRecentButton = (Button)mBaseView.findViewById(R.id.button_recent);
+        Button mContactButton = (Button)mBaseView.findViewById(R.id.button_contact);
 
         RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(mContext, 1);
         mRecyclerView.setHasFixedSize(true);
         mRecyclerView.setLayoutManager(mLayoutManager);
 
-        mRecyclerAdapter = new ContactsRecyclerAdapter(mContext, recentList, contactsList);
+        mRecyclerAdapter = new ContactsRecyclerAdapter(mContext, 0, recentList, contactsList);
         mRecyclerAdapter.setListOnClickListener(listener);
         mRecyclerView.setAdapter(mRecyclerAdapter);
+
+        mRecentButton.setOnClickListener(new View.OnClickListener() {
+            @SuppressLint("NotifyDataSetChanged")
+            @Override
+            public void onClick(View v) {
+                //((GridLayoutManager) mLayoutManager).setSpanCount(1);
+                mRecyclerAdapter.setViewType(0);
+                //mRecyclerAdapter.notifyDataSetChanged();
+                mRecyclerAdapter.notifyAll();
+            }
+        });
+        mContactButton.setOnClickListener(new View.OnClickListener() {
+            @SuppressLint("NotifyDataSetChanged")
+            @Override
+            public void onClick(View v) {
+                //((GridLayoutManager) mLayoutManager).setSpanCount(2);
+                mRecyclerAdapter.setViewType(1);
+                //mRecyclerAdapter.notifyDataSetChanged();
+                mRecyclerAdapter.notifyAll();
+            }
+        });
     }
 }

+ 29 - 0
app/src/main/res/layout/item_contact.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="70dp"
+    android:layout_height="70dp">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:orientation="vertical"
+        android:gravity="center"
+        >
+
+        <ImageView
+            android:layout_width="55dp"
+            android:layout_height="55dp"
+            android:src = "@mipmap/ic_launcher"
+            android:scaleType="fitXY"
+            android:id="@+id/contact_head"
+            />
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/contact_name"
+            android:visibility="gone"
+            />
+    </LinearLayout>
+
+</RelativeLayout>

+ 17 - 9
app/src/main/res/layout/view_screen_contacts.xml

@@ -5,29 +5,37 @@
     android:orientation="vertical"
     >
 
-    <LinearLayout
+    <RelativeLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:orientation="horizontal"
+        android:layout_marginTop="25dp"
         android:gravity="center_vertical"
         >
 
         <Button
-            android:layout_width="90dp"
-            android:layout_height="wrap_content"
+            android:id="@+id/button_recent"
+            android:layout_width="85dp"
+            android:layout_height="22dp"
+            android:layout_alignParentStart="true"
             android:text="@string/Contacts_Recent"
             android:textSize="9dp"
-            android:layout_marginStart="0dp"
+            android:drawableRight="@drawable/shape_switch_thumb_true"
+            android:backgroundTint="@color/xp_red"
+            style="@style/xp_style_button_right"
             />
 
         <Button
-            android:layout_width="90dp"
-            android:layout_height="wrap_content"
+            android:id="@+id/button_contact"
+            android:layout_width="85dp"
+            android:layout_height="22dp"
+            android:layout_alignParentEnd="true"
             android:text="@string/Contacts_Contacts"
             android:textSize="9dp"
-            android:layout_marginEnd="0dp"
+            android:drawableLeft="@drawable/shape_switch_thumb_true"
+            android:backgroundTint="@color/xp_red"
+            style="@style/xp_style_button_left"
             />
-    </LinearLayout>
+    </RelativeLayout>
 
     <androidx.recyclerview.widget.RecyclerView
         android:layout_width="wrap_content"