Переглянути джерело

优化搜索奖励与游戏界面用户体验

zengjiebin 7 роки тому
батько
коміт
66f0d3d202

+ 5 - 2
app/src/main/java/com/sheep/gamegroup/greendao/DDProviderHelper.java

@@ -574,10 +574,12 @@ public class DDProviderHelper {
     }
 
     /**
-     * 添加或更新搜索记录
-     * 添加成功返回true
      *
+     * 添加或更新搜索记录
+     * 添加或更新成功返回true
      * @param newInfo
+     * @param action1 参数 lastInfo为空时为添加数据,不为空时为更新数据
+     * @return
      */
     public boolean addOrUpdateSearchRecord(SearchRecord newInfo, Action1<SearchRecord> action1) {
         SearchRecordDao infoDao = getDaossion().getSearchRecordDao();
@@ -598,6 +600,7 @@ public class DDProviderHelper {
                 newInfo.setFirst_time(lastInfo.getLast_time());
                 newInfo.setCount(lastInfo.getCount() + newInfo.getCount());
                 infoDao.update(newInfo);
+                return true;
             }
         } catch (Exception e) {
             e.printStackTrace();

+ 12 - 4
app/src/main/java/com/sheep/gamegroup/view/activity/ActSearchAppOrTask.java

@@ -40,6 +40,7 @@ import java.util.List;
 import butterknife.BindView;
 import io.reactivex.android.schedulers.AndroidSchedulers;
 import io.reactivex.schedulers.Schedulers;
+import rx.functions.Action1;
 
 /**
  * Created by realicing on 2018/9/13.
@@ -94,7 +95,8 @@ public class ActSearchAppOrTask extends BaseActivity {
                                 recyclerView.setVisibility(View.VISIBLE);
                                 frame_container.setVisibility(View.INVISIBLE);
                             } else {
-                                frame_container.postDelayed(autoSearchRunnable, 1000L);//1秒后自动搜索
+                                long delay = textByClick ? 1L : 1000L;
+                                frame_container.postDelayed(autoSearchRunnable, delay);//1秒后自动搜索
                             }
                         })
                 .setRightBtn(this, "搜索", 0,
@@ -210,6 +212,7 @@ public class ActSearchAppOrTask extends BaseActivity {
                 view.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View view) {
+                        textByClick = true;
                         TitleBarUtils.getInstance().setSearchText(ActSearchAppOrTask.this, item.getInput());
                         if (item instanceof IHomePageSearch)
                             ApiUtil.postTopSearchStatisticsClickTopSearch((IHomePageSearch) item);
@@ -218,6 +221,7 @@ public class ActSearchAppOrTask extends BaseActivity {
             }
         }).setSort(sort));
     }
+    private boolean textByClick = false;//通过点击搜索历史或者热门推荐来搜索,应该立即执行
 
     //搜索历史中没有数据且没有获取到服务器的热门搜索列表
     private boolean isTitleInfoListEmpty() {
@@ -228,6 +232,7 @@ public class ActSearchAppOrTask extends BaseActivity {
 
     //尝试搜索游戏
     private void toSearchApp() {
+        textByClick = false;//重置
         if(fgtSearchAppOrTask == null){
             return;
         }
@@ -243,9 +248,12 @@ public class ActSearchAppOrTask extends BaseActivity {
             searchRecord.setInput(inputText);
             searchRecord.setLast_time(System.currentTimeMillis());
             searchRecord.setCount(1);
-            searchRecordList.add(searchRecord);
-            DDProviderHelper.getInstance().addOrUpdateSearchRecord(searchRecord, null);
-            ViewUtil.notifyDataSetChanged(recyclerView);
+            DDProviderHelper.getInstance().addOrUpdateSearchRecord(searchRecord, item -> {
+                if(item == null) {
+                    searchRecordList.add(searchRecord);
+                    ViewUtil.notifyDataSetChanged(recyclerView);
+                }
+            });
         }
         fgtSearchAppOrTask.toSearch(inputText);
     }

+ 21 - 6
app/src/main/java/com/sheep/gamegroup/view/fragment/BaseListFragment3.java

@@ -118,9 +118,9 @@ public abstract class BaseListFragment3<T> extends BaseRefreshLoadMoreFragment{
 
     //加载数据
     public void initData() {
-        initDataStatus = STATUS_ING;
         final String urlKey = getKey(page, per_page);
         if (isFirstGetACache()) {
+            initDataStatus = STATUS_CACHE;
             //先尝试获取缓存数据
             lastCacheList = DataUtil.getInstance().getCacheList(urlKey, getTClass(), conversion, page);
             loadList(lastCacheList);
@@ -137,6 +137,7 @@ public abstract class BaseListFragment3<T> extends BaseRefreshLoadMoreFragment{
                 }
             }
         });
+        initDataStatus = STATUS_NET;
         getApi(SheepApp.getInstance().getNetComponent().getApiService())
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
@@ -201,8 +202,10 @@ public abstract class BaseListFragment3<T> extends BaseRefreshLoadMoreFragment{
         lastMessage = null;
         setNoMore(false);
 
-        if (useSelfEmpty() && empty_view != null)
-            empty_view.setVisibility(View.INVISIBLE);
+        if (useSelfEmpty()) {
+            ViewUtil.setVisibility2(empty_view, true);
+            CommonUtil.getInstance().resetEmptyView(empty_view);
+        }
         list.clear();
         page = 1;
     }
@@ -235,8 +238,18 @@ public abstract class BaseListFragment3<T> extends BaseRefreshLoadMoreFragment{
 
     //是否显示无数据占位图
     protected void updateEmptyView() {
-        if (useSelfEmpty())
-            CommonUtil.getInstance().updateEmptyView(empty_view, list.isEmpty());
+        if (useSelfEmpty()) {
+            switch (initDataStatus){
+                case STATUS_CACHE:
+                    if(!list.isEmpty())
+                        CommonUtil.getInstance().updateEmptyView(empty_view, false);
+                    break;
+                case STATUS_NET:
+                default:
+                    CommonUtil.getInstance().updateEmptyView(empty_view, list.isEmpty());
+                    break;
+            }
+        }
     }
 
     protected abstract RecyclerView.Adapter getAdapter();
@@ -250,7 +263,9 @@ public abstract class BaseListFragment3<T> extends BaseRefreshLoadMoreFragment{
     protected int initDataStatus = STATUS_NONE;//加载数据的状态
     public static final int STATUS_NONE = 0;
     public static final int STATUS_ING = 1;
-    public static final int STATUS_FINISH = 2;
+    public static final int STATUS_CACHE = 2;//获取缓存数据中
+    public static final int STATUS_NET = 3;
+    public static final int STATUS_FINISH = 4;
     //是否正在刷新或者加载更多数据
     public boolean isLoadingData(){
         return initDataStatus == STATUS_ING;

+ 11 - 5
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtSearchAppOrTask.java

@@ -10,10 +10,14 @@ import com.sheep.gamegroup.model.api.ApiService;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.HomePageSearch;
 import com.sheep.gamegroup.util.ApiUtil;
+import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.ListUtil;
+import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.gamegroup.view.adapter.HomePageSearchAdapter;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.Locale;
 
 import io.reactivex.Observable;
@@ -41,7 +45,13 @@ public class FgtSearchAppOrTask extends BaseListFragment3<HomePageSearch> implem
 
     @Override
     protected String getKey(int page, int per_page) {
-        return String.format(Locale.CHINA, "app/top_search_statistics/home_page_search?search_content=%s", search_content);
+        String sc = search_content;
+        try {
+            sc = URLEncoder.encode(search_content,"utf-8");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        return String.format(Locale.CHINA, "app/top_search_statistics/home_page_search?search_content=%s", sc);
     }
 
     @Override
@@ -54,10 +64,6 @@ public class FgtSearchAppOrTask extends BaseListFragment3<HomePageSearch> implem
         return HomePageSearch.class;
     }
 
-    public void clear() {
-        list.clear();
-    }
-
     @Override
     public void toSearch(String name) {
         this.search_content = name;