This repository has been archived by the owner on Dec 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
180 additions
and
2 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
magnetic/src/main/java/com/magnetic/manager/DBManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.magnetic.manager; | ||
|
||
import com.framework.utils.UIUtils; | ||
import com.magnetic.mvp.model.DaoMaster; | ||
import com.magnetic.mvp.model.DaoSession; | ||
import com.magnetic.mvp.model.SearchModel; | ||
import com.magnetic.mvp.model.SearchModelDao; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* by y on 2017/6/21. | ||
*/ | ||
|
||
public class DBManager { | ||
private DBManager() { | ||
} | ||
|
||
private static final String SQL_NAME = "magnetic"; | ||
|
||
private static class SessionHolder { | ||
private static final DaoSession daoSession = new DaoMaster( | ||
new DaoMaster.DevOpenHelper(UIUtils.getContext(), SQL_NAME, null).getWritableDatabase()).newSession(); | ||
} | ||
|
||
public static boolean isEmpty(String key) { | ||
return SessionHolder.daoSession.getSearchModelDao().queryBuilder().where(SearchModelDao.Properties.SearchContent.eq(key)).unique() == null; | ||
} | ||
|
||
public static List<SearchModel> getSearchContent() { | ||
return SessionHolder.daoSession.getSearchModelDao().loadAll(); | ||
} | ||
|
||
public static void insert(String markName) { | ||
SessionHolder.daoSession.getSearchModelDao().insert(new SearchModel(markName)); | ||
} | ||
|
||
public static void clear(String key) { | ||
SessionHolder.daoSession.getSearchModelDao().deleteByKey(key); | ||
} | ||
|
||
public static void clear() { | ||
SessionHolder.daoSession.getSearchModelDao().deleteAll(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
magnetic/src/main/java/com/magnetic/mvp/model/SearchModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.magnetic.mvp.model; | ||
|
||
import org.greenrobot.greendao.annotation.Entity; | ||
import org.greenrobot.greendao.annotation.Id; | ||
import org.greenrobot.greendao.annotation.Generated; | ||
|
||
/** | ||
* by y on 27/06/2017. | ||
*/ | ||
@Entity | ||
public class SearchModel { | ||
@Id | ||
private String searchContent; | ||
|
||
@Generated(hash = 947289422) | ||
public SearchModel(String searchContent) { | ||
this.searchContent = searchContent; | ||
} | ||
|
||
@Generated(hash = 506184495) | ||
public SearchModel() { | ||
} | ||
|
||
public String getSearchContent() { | ||
return this.searchContent; | ||
} | ||
|
||
public void setSearchContent(String searchContent) { | ||
this.searchContent = searchContent; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:autoMirrored="true" | ||
android:viewportHeight="24.0" | ||
android:viewportWidth="24.0"> | ||
<path | ||
android:fillColor="#fff" | ||
android:pathData="M17,3H7c-1.1,0 -1.99,0.9 -1.99,2L5,21l7,-3 7,3V5c0,-1.1 -0.9,-2 -2,-2z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:autoMirrored="true" | ||
android:viewportHeight="24.0" | ||
android:viewportWidth="24.0"> | ||
<path | ||
android:fillColor="#000" | ||
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:padding="10dp" | ||
android:background="?android:selectableItemBackground"> | ||
|
||
<android.support.v7.widget.AppCompatTextView | ||
android:id="@+id/tv_name" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerVertical="true" | ||
android:layout_margin="5dp" /> | ||
|
||
<android.support.v7.widget.AppCompatImageView | ||
android:id="@+id/iv_delete" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentRight="true" | ||
android:layout_centerVertical="true" | ||
android:background="@drawable/ic_delete" /> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
<item | ||
android:id="@+id/mark" | ||
android:icon="@drawable/ic_bookmark" | ||
android:title="@string/search_content" | ||
app:showAsAction="ifRoom" /> | ||
<item | ||
android:id="@+id/search" | ||
android:icon="@drawable/ic_search" | ||
android:title="@string/search_title" | ||
app:showAsAction="ifRoom" /> | ||
|
||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters