Merge branch 'dev'

This commit is contained in:
Tariel Hlontsi 2016-09-10 19:21:11 +03:00
commit 493e3c1f10
132 changed files with 2080 additions and 772 deletions

View File

@ -5,7 +5,6 @@
<GradleProjectSettings> <GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="1.8" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

View File

@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android { android {
compileSdkVersion 23 compileSdkVersion 23
buildToolsVersion "23.0.1" buildToolsVersion "23.0.3"
/* /*
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
@ -18,7 +18,7 @@ android {
} }
buildTypes { buildTypes {
release { release {
minifyEnabled false minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
@ -31,9 +31,6 @@ repositories {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.6.2' compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.1' compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1' compile 'com.squareup.retrofit2:converter-gson:2.0.1'
@ -44,4 +41,6 @@ dependencies {
compile 'com.android.support:design:23.3.0' compile 'com.android.support:design:23.3.0'
compile 'com.android.support:cardview-v7:23.3.0' compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.facebook.android:facebook-android-sdk:4.11.0' compile 'com.facebook.android:facebook-android-sdk:4.11.0'
compile files('libs/socialauth-4.4.jar')
compile files('libs/socialauth-android-3.2.jar')
} }

View File

@ -15,3 +15,35 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *; # public *;
#} #}
-keep public class java.nio.file.* { public *; }
-dontwarn java.nio.file.**
-keep public class org.codehaus.mojo.animal_sniffer.* { public *; }
-dontwarn org.codehaus.mojo.animal_sniffer.**
-keep public class org.openid4java.consumer.* { public *; }
-dontwarn org.openid4java.consumer.**
-keep public class org.openid4java.message.* { public *; }
-dontwarn org.openid4java.message.**
-keep public class org.openid4java.OpenIDException { public *; }
-dontwarn org.openid4java.OpenIDException
-keep public class org.openid4java.discovery.Identifier { public *; }
-dontwarn org.openid4java.discovery.Identifier
-keep public class javax.servlet.http.HttpServletRequest { public *; }
-dontwarn javax.servlet.http.HttpServletRequest
-keep public class java.lang.invoke.* { public *; }
-dontwarn java.lang.invoke.**
-keep public class org.openid4java.discovery.DiscoveryInformation { public *; }
-dontwarn org.openid4java.discovery.DiscoveryInformation
-dontwarn retrofit2.Platform$Java8

View File

@ -14,7 +14,7 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/> <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<activity android:name="com.hikapro.backpack.MainActivity"> <activity android:name="com.hikapro.backpack.MainActivity" android:screenOrientation="portrait">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@ -0,0 +1 @@
[{"id":2,"photo":"http://hikapro.com/system/backpack/sharing_photos/photos/000/000/002/large/thumb_IMG_2899_1024.jpg?1449590757","photo_thumb":"http://hikapro.com/system/backpack/sharing_photos/photos/000/000/002/thumb/thumb_IMG_2899_1024.jpg?1449590757"}]

View File

@ -0,0 +1,51 @@
#google
www.google.com.consumer_key = socialauth.in
www.google.com.consumer_secret = Mlt6oDI0iIoOiylfiqgnCkrS
#yahoo
api.login.yahoo.com.consumer_key = dj0yJmk9Nlpqd0pIMENnb1N4JmQ9WVdrOWJqbEhURXA0TTJVbWNHbzlNVEk0TXpNeE5EYzJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0yOA--
api.login.yahoo.com.consumer_secret = c04675a9274fb556f9e817b1ad23f0c91c2c0500
#twitter
twitter.com.consumer_key = RbtJOnWBSf9hLYKiw6R5qa2g4
twitter.com.consumer_secret = dyd9Kv7ITZhpYL0FpK9ozUNSgjvHM4lDBg7K2domssdc3p6iPv
#facebook
graph.facebook.com.consumer_key = 297841130364674
graph.facebook.com.consumer_secret = dc9c59d0c72d4f2533580e80ba4c2a59
#LinkedIn
api.linkedin.com.consumer_key = bh82t52rdos6
api.linkedin.com.consumer_secret = zQ1LLrGbhDZ36fH8
#FourSquare
foursquare.com.consumer_key = VJT0YKBEQAQOMPWZPTGF1V5WOHZQMWNNJEBBQBSDNU3COOMQ
foursquare.com.consumer_secret = HCVBO1W5MNWIPAOJABI3LILMLTHTPR52RU3P0GJ3TYTYVBWU
#MySpace
api.myspace.com.consumer_key = 67cc035edf0f4387a2488a0fb0b490ab
api.myspace.com.consumer_secret = 80b58c4873ac4d2e8edb6257d85c79e71692c39d5f0f4b3a90acc1dffaf58cda
#Runkeeper
runkeeper.com.consumer_key=b1320c16082d48e2a7a94f5bfa2ce58b
runkeeper.com.consumer_secret=7cbf7688519d4e8cb5343a4c939ac1a6
#Yammer
www.yammer.com.consumer_key=wLR96V3qBPHPcYLkrLvgg
www.yammer.com.consumer_secret=4hhUOP6tYiHNOUz6dMhWBVHgcsFq3MUZpI8IkA
#Salesforce
login.salesforce.com.consumer_key = 3MVG9Y6d_Btp4xp4yFMR0tPSndvoapjV0sIbnVSNLg_l1vkeDgLelQhr6iYwlTgCL98VSBjU_XvQZYGfSmW_D
login.salesforce.com.consumer_secret = 4962202263932085201
#Google Plus
googleapis.com.consumer_key=505071246058-6i3hf3rhd1s0qst492e23g9sq5t9koiv.apps.googleusercontent.com
googleapis.com.consumer_secret=xrNQTx9ELsxmyUBfh35ntpfR
#Flickr
www.flickr.com.consumer_key = c519f64dbddc50f3e25e8cc73744602b
www.flickr.com.consumer_secret = bf1a181c42bef4ea
#Instagram
api.instagram.com.consumer_key = c28ba7d08da64462a0db848c366ea43e
api.instagram.com.consumer_secret = c5063d4e5f1248a19d2fa3e8bf3d8d6e

View File

@ -40,9 +40,6 @@ public class MainActivity extends Activity implements View.ActivityCallback {
private final StateMaintainer stateMaintainer = private final StateMaintainer stateMaintainer =
new StateMaintainer(getFragmentManager(), MainActivity.class.getName()); new StateMaintainer(getFragmentManager(), MainActivity.class.getName());
// life cycle -->
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
boolean ret; boolean ret;
@ -179,8 +176,6 @@ public class MainActivity extends Activity implements View.ActivityCallback {
super.onDestroy(); super.onDestroy();
Log.i("onDestroy", "Activity"); Log.i("onDestroy", "Activity");
} }
// life cycle <--
@Override @Override
public void startSetListFragment() { public void startSetListFragment() {

View File

@ -13,7 +13,6 @@ import java.util.HashMap;
*/ */
public class StateMaintainer { public class StateMaintainer {
protected final String TAG = getClass().getSimpleName();
private final String stateMaintainerTag; private final String stateMaintainerTag;
private final WeakReference<FragmentManager> fragmentManager; private final WeakReference<FragmentManager> fragmentManager;
private StateMngFragment stateMngFragment; private StateMngFragment stateMngFragment;
@ -72,7 +71,6 @@ public class StateMaintainer {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Grants that the fragment will be preserved
setRetainInstance(true); setRetainInstance(true);
} }
@ -89,7 +87,6 @@ public class StateMaintainer {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T get(String key) { public <T> T get(String key) {
Log.i(this.toString(), String.format("Get object %s Total count %d", key, data.size()));
return (T) data.get(key); return (T) data.get(key);
} }
} }

View File

@ -29,7 +29,6 @@ public class AddModel implements Model.Add {
this.filteredItems = new ArrayList<>(256); this.filteredItems = new ArrayList<>(256);
this.categoriesCache = new ArrayList<>(20); this.categoriesCache = new ArrayList<>(20);
this.dao = DAO.getInstance(); this.dao = DAO.getInstance();
dao.registerObserver(this);
} }
@Override @Override
@ -72,11 +71,13 @@ public class AddModel implements Model.Add {
if ( !isConfigurationChanging ) { if ( !isConfigurationChanging ) {
presenter = null; presenter = null;
} }
dao.unregisterObserver(this);
} }
@Override @Override
public void executeQuery() { public void executeQuery() {
Message command; Message command;
dao.registerObserver(this);
if (categoriesCache.isEmpty()) { if (categoriesCache.isEmpty()) {
command = Message.obtain(); command = Message.obtain();
command.what = Command.ITEM_GET_CATEGORIES; command.what = Command.ITEM_GET_CATEGORIES;

View File

@ -2,10 +2,12 @@ package com.hikapro.backpack.model;
import java.util.List; import java.util.List;
import com.hikapro.backpack.model.dao.Db;
import com.hikapro.backpack.model.entities.Category; import com.hikapro.backpack.model.entities.Category;
import com.hikapro.backpack.model.entities.Item; import com.hikapro.backpack.model.entities.Item;
import com.hikapro.backpack.model.entities.Set; import com.hikapro.backpack.model.entities.Set;
import com.hikapro.backpack.model.entities.SharingPicture;
import com.hikapro.backpack.model.entities.Timestamp; import com.hikapro.backpack.model.entities.Timestamp;
import com.hikapro.backpack.model.entities.Updates; import com.hikapro.backpack.model.entities.Updates;
import retrofit2.Call; import retrofit2.Call;
@ -32,5 +34,6 @@ public interface Api {
@GET("api/v1/backpack/updates/all") @GET("api/v1/backpack/updates/all")
Call<Updates> getUpdates(@Query("timestamp") long timestamp); Call<Updates> getUpdates(@Query("timestamp") long timestamp);
@GET("api/v1/backpack/sharing_photos")
Call<List<SharingPicture>> getSharingPicture();
} }

View File

@ -10,12 +10,14 @@ import java.util.Hashtable;
import java.util.List; import java.util.List;
import com.hikapro.backpack.App; import com.hikapro.backpack.App;
import com.hikapro.backpack.R;
import com.hikapro.backpack.model.dao.Command; import com.hikapro.backpack.model.dao.Command;
import com.hikapro.backpack.model.dao.DAO; import com.hikapro.backpack.model.dao.DAO;
import com.hikapro.backpack.model.dao.Event; import com.hikapro.backpack.model.dao.Event;
import com.hikapro.backpack.model.entities.Category; import com.hikapro.backpack.model.entities.Category;
import com.hikapro.backpack.model.entities.Item; import com.hikapro.backpack.model.entities.Item;
import com.hikapro.backpack.presenter.Presenter; import com.hikapro.backpack.presenter.Presenter;
import com.hikapro.backpack.presenter.adapters.helper.AppRater;
/** /**
* Created by tariel on 22/04/16. * Created by tariel on 22/04/16.
@ -32,6 +34,7 @@ public class ItemModel implements Model.Item {
protected List<Item> itemsCache; protected List<Item> itemsCache;
protected Hashtable<Category, List<Item>> items; protected Hashtable<Category, List<Item>> items;
protected int lastVisiblePosition;
public ItemModel() { public ItemModel() {
this.categoriesCache = new Hashtable<>(20, 0.9f); this.categoriesCache = new Hashtable<>(20, 0.9f);
@ -126,7 +129,11 @@ public class ItemModel implements Model.Item {
break; break;
case Event.SET_RESTORE_COMPLETED: case Event.SET_RESTORE_COMPLETED:
executeQuery(); executeQuery();
Toast.makeText(App.getAppContext(), "Restore completed", Toast.LENGTH_SHORT).show(); Toast.makeText(App.getAppContext(), R.string.restore_completed, Toast.LENGTH_SHORT).show();
break;
case Event.NEED_TO_RATE_NOW:
if (presenter != null)
presenter.showRateDialog();
break; break;
} }
} }
@ -141,7 +148,7 @@ public class ItemModel implements Model.Item {
command.arg1 = currentSet; command.arg1 = currentSet;
dao.executeCommand(command); dao.executeCommand(command);
if (categoriesCache.isEmpty()) { if (categoriesCache == null || categoriesCache.isEmpty()) {
command = Message.obtain(); command = Message.obtain();
command.what = Command.ITEM_GET_CATEGORIES; command.what = Command.ITEM_GET_CATEGORIES;
dao.executeCommand(command); dao.executeCommand(command);
@ -157,8 +164,6 @@ public class ItemModel implements Model.Item {
dao.executeCommand(command); dao.executeCommand(command);
} }
// categories -->
@Override @Override
public Category getCategoryByPosition(int position) { public Category getCategoryByPosition(int position) {
Category ret = null; Category ret = null;
@ -166,21 +171,15 @@ public class ItemModel implements Model.Item {
return ret; return ret;
} }
// categories <--
// items --> public int getLastVisiblePosition() {
return lastVisiblePosition < 0 ? 0 : lastVisiblePosition;
}
@Override public void setLastVisiblePosition(int lastVisiblePosition) {
public Item findItem(int id) { this.lastVisiblePosition = lastVisiblePosition;
Item item = null;
for (Item i : itemsCache) {
if (i.getId() == id) {
item = i;
break;
}
}
return item;
} }
@Override @Override
public Item getItemByPosition(int position) { public Item getItemByPosition(int position) {
Item ret = null; Item ret = null;
@ -217,7 +216,7 @@ public class ItemModel implements Model.Item {
@Override @Override
public int getItemsCount() { public int getItemsCount() {
return itemsCache.size(); return itemsCache == null ? 0 : itemsCache.size();
} }
@Override @Override
@ -229,9 +228,6 @@ public class ItemModel implements Model.Item {
public int getPackedQty() { public int getPackedQty() {
return packedQty; return packedQty;
} }
// items <--
// events -->
@Override @Override
public void notifyDataSetChanged() { public void notifyDataSetChanged() {
@ -243,12 +239,11 @@ public class ItemModel implements Model.Item {
public void onDestroy(boolean isConfigurationChanging) { public void onDestroy(boolean isConfigurationChanging) {
if ( !isConfigurationChanging ) { if ( !isConfigurationChanging ) {
presenter = null; presenter = null;
categoriesCache = null;
itemsCache = null;
} }
dao.unregisterObserver(this); dao.unregisterObserver(this);
} }
// events <--
// process -->
@Override @Override
public void pendingRemove(Item item) { public void pendingRemove(Item item) {
@ -258,7 +253,6 @@ public class ItemModel implements Model.Item {
command.arg1 = currentSet; command.arg1 = currentSet;
command.arg2 = item.getId(); command.arg2 = item.getId();
dao.executeCommand(command); dao.executeCommand(command);
//itemsCache.remove(item);// TODO check nn
} }
} }
@ -270,7 +264,6 @@ public class ItemModel implements Model.Item {
command.arg1 = currentSet; command.arg1 = currentSet;
command.arg2 = item.getId(); command.arg2 = item.getId();
dao.executeCommand(command); dao.executeCommand(command);
//itemsCache.remove(item);
} }
} }
@ -282,7 +275,6 @@ public class ItemModel implements Model.Item {
command.arg1 = currentSet; command.arg1 = currentSet;
command.arg2 = item.getId(); command.arg2 = item.getId();
dao.executeCommand(command); dao.executeCommand(command);
//itemsCache.remove(item);
} }
} }
@Override @Override
@ -320,17 +312,12 @@ public class ItemModel implements Model.Item {
dao.executeCommand(command); dao.executeCommand(command);
} }
// process <--
// other -->
@Override @Override
public void setPresenter(Presenter.ItemList presenter) { public void setPresenter(Presenter.ItemList presenter) {
this.presenter = presenter; this.presenter = presenter;
this.currentSet = presenter.getCurrentSet().getId(); this.currentSet = presenter.getCurrentSet().getId();
this.currentSetActiveItemsQty = presenter.getCurrentSet().getActiveQty(); this.currentSetActiveItemsQty = presenter.getCurrentSet().getActiveQty();
//dao.registerObserver(this);
} }
@Override @Override
@ -338,5 +325,4 @@ public class ItemModel implements Model.Item {
return presenter; return presenter;
} }
// other <--
} }

View File

@ -27,16 +27,17 @@ public interface Model {
int getSetsCount(); int getSetsCount();
void setPresenter(Presenter.SetList presenter); void setPresenter(Presenter.SetList presenter);
Presenter.SetList getPresenter(); Presenter.SetList getPresenter();
//GLM int getLastVisiblePosition();
List<com.hikapro.backpack.model.entities.Set> getSets(); // tag renamed void setLastVisiblePosition(int position);
List<com.hikapro.backpack.model.entities.Set> getSets();
void setsReorderNotify(); void setsReorderNotify();
} }
interface Item extends Base { interface Item extends Base {
void filter(String query); void filter(String query);
int getHeaderId(int position);//TODO review int getHeaderId(int position);
int getItemId(int position);//TODO review int getItemId(int position);
// leave at home // leave at home
void pendingRemove(com.hikapro.backpack.model.entities.Item item); void pendingRemove(com.hikapro.backpack.model.entities.Item item);
void pendingRemoveCancel(com.hikapro.backpack.model.entities.Item item); void pendingRemoveCancel(com.hikapro.backpack.model.entities.Item item);
@ -45,7 +46,9 @@ public interface Model {
int getActiveItemsCount(); int getActiveItemsCount();
int getPackedQty(); int getPackedQty();
com.hikapro.backpack.model.entities.Item findItem(int id); int getLastVisiblePosition();
void setLastVisiblePosition(int position);
com.hikapro.backpack.model.entities.Item getItemByPosition(int position); com.hikapro.backpack.model.entities.Item getItemByPosition(int position);
com.hikapro.backpack.model.entities.Category getCategoryByPosition(int position); com.hikapro.backpack.model.entities.Category getCategoryByPosition(int position);
@ -74,6 +77,7 @@ public interface Model {
interface Share extends Base { interface Share extends Base {
void setPresenter(Presenter.Share presenter); void setPresenter(Presenter.Share presenter);
Presenter.Share getPresenter(); Presenter.Share getPresenter();
Bitmap[] getSharingPics();
} }

View File

@ -1,6 +1,8 @@
package com.hikapro.backpack.model; package com.hikapro.backpack.model;
import android.Manifest;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
@ -40,4 +42,16 @@ public class NetworkUtil {
return activeNetwork.getType(); return activeNetwork.getType();
//ConnectivityManager.TYPE_WIFI; //ConnectivityManager.TYPE_WIFI;
} }
public static boolean isNetworkAvailable(Context context) {
if (context.checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) {
return false;
}
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = connMgr.getActiveNetworkInfo();
return netInfo != null && netInfo.isConnected();
}
} }

View File

@ -8,10 +8,12 @@ import java.util.Hashtable;
import java.util.List; import java.util.List;
import com.hikapro.backpack.App; import com.hikapro.backpack.App;
import com.hikapro.backpack.R;
import com.hikapro.backpack.model.dao.Command; import com.hikapro.backpack.model.dao.Command;
import com.hikapro.backpack.model.dao.Event; import com.hikapro.backpack.model.dao.Event;
import com.hikapro.backpack.model.entities.Category; import com.hikapro.backpack.model.entities.Category;
import com.hikapro.backpack.model.entities.Item; import com.hikapro.backpack.model.entities.Item;
import com.hikapro.backpack.presenter.adapters.helper.AppRater;
/** /**
* Created by tariel on 12/05/16. * Created by tariel on 12/05/16.
@ -26,7 +28,7 @@ public class PackedModel extends ItemModel {
public void executeQuery() { public void executeQuery() {
Message command; Message command;
dao.registerObserver(this); dao.registerObserver(this);
if (categoriesCache.isEmpty()) { if (categoriesCache == null || categoriesCache.isEmpty()) {
command = Message.obtain(); command = Message.obtain();
command.what = Command.ITEM_GET_CATEGORIES; command.what = Command.ITEM_GET_CATEGORIES;
dao.executeCommand(command); dao.executeCommand(command);
@ -128,7 +130,11 @@ public class PackedModel extends ItemModel {
break; break;
case Event.SET_RESTORE_COMPLETED: case Event.SET_RESTORE_COMPLETED:
executeQuery(); executeQuery();
Toast.makeText(App.getAppContext(), "Restore completed", Toast.LENGTH_SHORT).show(); Toast.makeText(App.getAppContext(), R.string.restore_completed, Toast.LENGTH_SHORT).show();
break;
case Event.NEED_TO_RATE_NOW:
if (presenter != null)
presenter.showRateDialog();
break; break;
} }
} }

View File

@ -23,15 +23,21 @@ public class SetModel implements Model.Set {
private List<com.hikapro.backpack.model.entities.Set> cache; private List<com.hikapro.backpack.model.entities.Set> cache;
private Presenter.SetList presenter; private Presenter.SetList presenter;
private DAO dao; private DAO dao;
private int lastVisiblePosition;
public SetModel() { public SetModel() {
this.cache = new ArrayList<>(); this.cache = new ArrayList<>();
this.dao = DAO.getInstance(); this.dao = DAO.getInstance();
dao.registerObserver(this);
} }
//region sets public int getLastVisiblePosition() {
return lastVisiblePosition < 0 ? 0 : lastVisiblePosition;
}
public void setLastVisiblePosition(int lastVisiblePosition) {
this.lastVisiblePosition = lastVisiblePosition;
}
@Override @Override
public com.hikapro.backpack.model.entities.Set getSetByPosition(int position) { public com.hikapro.backpack.model.entities.Set getSetByPosition(int position) {
@ -54,28 +60,21 @@ public class SetModel implements Model.Set {
return cache.size(); return cache.size();
} }
//endregion
//region events
@Override @Override
public void onDestroy(boolean isConfigurationChanging) { public void onDestroy(boolean isConfigurationChanging) {
if ( !isConfigurationChanging ) { if ( !isConfigurationChanging ) {
presenter = null; presenter = null;
} }
dao.unregisterObserver(this);
} }
@Override @Override
public void notifyDataSetChanged() { public void notifyDataSetChanged() {
presenter.notifyDataSetChanged(); presenter.notifyDataSetChanged();
} }
//endregion
//region process
@Override @Override
public void executeQuery() { public void executeQuery() {
dao.registerObserver(this);
if (presenter != null) if (presenter != null)
presenter.startProgress(); presenter.startProgress();
Message command = Message.obtain(); Message command = Message.obtain();
@ -136,9 +135,6 @@ public class SetModel implements Model.Set {
command.obj = cache; command.obj = cache;
dao.executeCommand(command); dao.executeCommand(command);
} }
//endregion
//region other
@Override @Override
public void setPresenter(Presenter.SetList presenter) { public void setPresenter(Presenter.SetList presenter) {
@ -150,11 +146,6 @@ public class SetModel implements Model.Set {
return presenter; return presenter;
} }
//endregion
//GLM
@Override @Override
public List<com.hikapro.backpack.model.entities.Set> getSets() public List<com.hikapro.backpack.model.entities.Set> getSets()
{ {

View File

@ -1,10 +1,22 @@
package com.hikapro.backpack.model; package com.hikapro.backpack.model;
import android.graphics.Bitmap;
import android.os.Message; import android.os.Message;
import android.widget.Toast;
import com.hikapro.backpack.App;
import com.hikapro.backpack.R;
import com.hikapro.backpack.model.dao.Command;
import com.hikapro.backpack.model.dao.DAO; import com.hikapro.backpack.model.dao.DAO;
import com.hikapro.backpack.model.dao.Event;
import com.hikapro.backpack.model.entities.Category;
import com.hikapro.backpack.model.entities.Item;
import com.hikapro.backpack.presenter.Presenter; import com.hikapro.backpack.presenter.Presenter;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
/** /**
* Created by tariel on 16/05/16. * Created by tariel on 16/05/16.
*/ */
@ -12,30 +24,56 @@ public class ShareModel implements Model.Share {
private Presenter.Share presenter; private Presenter.Share presenter;
private DAO dao; private DAO dao;
private Bitmap[] picCache;
public ShareModel() { public ShareModel() {
this.dao = DAO.getInstance(); this.dao = DAO.getInstance();
dao.registerObserver(this);
} }
@Override @Override
public void onDestroy(boolean isConfigurationChanging) { public void onDestroy(boolean isConfigurationChanging) {
if ( !isConfigurationChanging ) {
presenter = null;
}
dao.unregisterObserver(this);
} }
@Override @Override
public void executeQuery() { public void executeQuery() {
if (picCache == null) {
Message command;
dao.registerObserver(this);
command = Message.obtain();
command.what = Command.SHARING_GET_PIC;
dao.executeCommand(command);
} else
notifyDataSetChanged();
} }
@Override @Override
public void notifyDataSetChanged() { public void notifyDataSetChanged() {
if (presenter != null)
presenter.notifyDataSetChanged();
} }
@Override @Override
public void onEvent(Message event) { public void onEvent(Message event) {
switch (event.what) {
case Event.SHARING_GET_PIC_ERROR:
if (!NetworkUtil.isInternetAvailable()) {
Toast.makeText(App.getAppContext(), R.string.no_connection, Toast.LENGTH_SHORT).show();
}
notifyDataSetChanged();
break;
case Event.SHARING_PIC_LOADED:
picCache = (Bitmap[]) event.obj;
notifyDataSetChanged();
break;
}
} }
@Override @Override
@ -47,4 +85,8 @@ public class ShareModel implements Model.Share {
public Presenter.Share getPresenter() { public Presenter.Share getPresenter() {
return presenter; return presenter;
} }
public Bitmap[] getSharingPics() {
return picCache;
}
} }

View File

@ -5,11 +5,6 @@ package com.hikapro.backpack.model.dao;
*/ */
public interface Command { public interface Command {
int SET_SCOPE_END = 0x77;
int ITEM_SCOPE_END = 0x8B;
int MY_LIST_SCOPE_END = 0x9F;
int SET_GET_ALL = 0x64; int SET_GET_ALL = 0x64;
int SET_REORDER = 0x65; int SET_REORDER = 0x65;
int SET_GET_ITEMS = 0x66; int SET_GET_ITEMS = 0x66;
@ -32,15 +27,10 @@ public interface Command {
int ITEM_REMOVAL_CANCEL = 0x80; int ITEM_REMOVAL_CANCEL = 0x80;
int ITEM_READ = 0x81; int ITEM_READ = 0x81;
int MY_LIST_POST = 0x8C; int SHARING_GET_PIC = 0x8C;
int MY_LIST_ITEM_ADD = 0x8D;
int MY_LIST_ITEM_DELETE = 0x8E;
int MY_LIST_CLEAR = 0x8F;
int SYNC = 0xA0; int SYNC = 0xA0;
int SYNC_IF_NOT_EXISTS = 0xA1; int SYNC_IF_NOT_EXISTS = 0xA1;
int SYNC_READ_FROM_FILE = 0xA2; int SYNC_READ_FROM_FILE = 0xA2;
int TEST = 0xC8;
} }

View File

@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.hikapro.backpack.App; import com.hikapro.backpack.App;
import com.hikapro.backpack.R;
import com.hikapro.backpack.model.Api; import com.hikapro.backpack.model.Api;
import com.hikapro.backpack.model.Model; import com.hikapro.backpack.model.Model;
import com.hikapro.backpack.model.NetworkUtil; import com.hikapro.backpack.model.NetworkUtil;
@ -40,8 +41,10 @@ import com.hikapro.backpack.model.SetModel;
import com.hikapro.backpack.model.entities.Category; import com.hikapro.backpack.model.entities.Category;
import com.hikapro.backpack.model.entities.Item; import com.hikapro.backpack.model.entities.Item;
import com.hikapro.backpack.model.entities.Set; import com.hikapro.backpack.model.entities.Set;
import com.hikapro.backpack.model.entities.SharingPicture;
import com.hikapro.backpack.model.entities.Timestamp; import com.hikapro.backpack.model.entities.Timestamp;
import com.hikapro.backpack.model.entities.UpdateLog; import com.hikapro.backpack.model.entities.UpdateLog;
import com.hikapro.backpack.presenter.adapters.helper.AppRater;
import retrofit2.Response; import retrofit2.Response;
@ -55,15 +58,12 @@ public class DAO {
private static final int KEEP_ALIVE_TIME = 1; private static final int KEEP_ALIVE_TIME = 1;
private static final TimeUnit KEEP_ALIVE_TIME_UNIT = TimeUnit.SECONDS; private static final TimeUnit KEEP_ALIVE_TIME_UNIT = TimeUnit.SECONDS;
private static final int MY_LIST_ID = 15;
//endregion //endregion
private static DAO instance; private static DAO instance;
private final ThreadPoolExecutor threadPool; private final ThreadPoolExecutor threadPool;
private final Handler handler; private final Handler handler;
private SetModel setModel;
private final Api api; private final Api api;
private Context context; private Context context;
private DbHelper helper; private DbHelper helper;
@ -278,16 +278,10 @@ public class DAO {
threadPool.execute(itemTask); threadPool.execute(itemTask);
break; break;
case Command.MY_LIST_ITEM_ADD : case Command.SHARING_GET_PIC:
break; imageProviderTask = new ImageProviderTask(Command.SHARING_GET_PIC,
Process.THREAD_PRIORITY_MORE_FAVORABLE);
case Command.MY_LIST_ITEM_DELETE : threadPool.execute(imageProviderTask);
break;
case Command.MY_LIST_POST :
break;
case Command.MY_LIST_CLEAR :
break; break;
case Command.SYNC: case Command.SYNC:
@ -329,6 +323,26 @@ public class DAO {
values = Db.LogTable.toContentValues(timestamp); values = Db.LogTable.toContentValues(timestamp);
db.insert(Db.LogTable.TABLE_NAME, null, values); db.insert(Db.LogTable.TABLE_NAME, null, values);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (Exception ex) {
Log.e("Insert Timestamp", ex.getMessage());
} finally {
db.endTransaction();
db.close();
}
}
}
private void insertSharingPic(SharingPicture sharingPicture) {
if (sharingPicture != null) {
ContentValues values;
SQLiteDatabase db = getWriteDB();
try {
db.beginTransaction();
values = Db.SharingPicsTable.toContentValues(sharingPicture);
db.insert(Db.SharingPicsTable.TABLE_NAME, null, values);
db.setTransactionSuccessful();
} catch (Exception ex) {
Log.e("Inserting sharing photo", ex.getMessage());
} finally { } finally {
db.endTransaction(); db.endTransaction();
db.close(); db.close();
@ -347,6 +361,8 @@ public class DAO {
db.insert(Db.ItemsTable.TABLE_NAME, null, values); db.insert(Db.ItemsTable.TABLE_NAME, null, values);
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (Exception ex) {
Log.e("Insert Items", ex.getMessage());
} finally { } finally {
db.endTransaction(); db.endTransaction();
db.close(); db.close();
@ -390,6 +406,8 @@ public class DAO {
} else { } else {
ret = item.getId(); ret = item.getId();
} }
} catch (Exception ex) {
Log.e("Insert Item", ex.getMessage());
} finally { } finally {
if (cursor != null) if (cursor != null)
cursor.close(); cursor.close();
@ -414,6 +432,8 @@ public class DAO {
db.insert(Db.CategoriesTable.TABLE_NAME, null, values); db.insert(Db.CategoriesTable.TABLE_NAME, null, values);
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (Exception ex) {
Log.e("Insert Categories", ex.getMessage());
} finally { } finally {
db.endTransaction(); db.endTransaction();
db.close(); db.close();
@ -436,6 +456,8 @@ public class DAO {
++i; ++i;
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (Exception ex) {
Log.e("Insert Sets", ex.getMessage());
} finally { } finally {
db.endTransaction(); db.endTransaction();
db.close(); db.close();
@ -455,6 +477,8 @@ public class DAO {
db.insert(Db.SetItemsTable.TABLE_NAME, null, values); db.insert(Db.SetItemsTable.TABLE_NAME, null, values);
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (Exception ex) {
Log.e("Insert Set Items", ex.getMessage());
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
@ -471,6 +495,8 @@ public class DAO {
values = Db.SetItemsTable.toContentValues(setId, itemId, userDefined); values = Db.SetItemsTable.toContentValues(setId, itemId, userDefined);
ret = db.insert(Db.SetItemsTable.TABLE_NAME, null, values); ret = db.insert(Db.SetItemsTable.TABLE_NAME, null, values);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (Exception ex) {
Log.e("Insert Set Item", ex.getMessage());
} finally { } finally {
db.endTransaction(); db.endTransaction();
db.close(); db.close();
@ -501,6 +527,30 @@ public class DAO {
cursor = db.rawQuery(q,null); cursor = db.rawQuery(q,null);
if (cursor.moveToNext()) if (cursor.moveToNext())
ret = Db.LogTable.parseCursor(cursor); ret = Db.LogTable.parseCursor(cursor);
} catch (Exception ex) {
Log.e("Update Log", ex.getMessage());
} finally {
if (cursor != null)
cursor.close();
if (db != null)
db.close();
}
return ret;
}
private SharingPicture readLastSharingPic() {
SharingPicture ret = null;
SQLiteDatabase db = null;
Cursor cursor = null;
try {
db = getReadDB();
String q = String.format("SELECT * FROM %s ORDER BY %s DESC LIMIT 1",
Db.SharingPicsTable.TABLE_NAME, Db.SharingPicsTable.COLUMN_ID);
cursor = db.rawQuery(q,null);
if (cursor.moveToNext())
ret = Db.SharingPicsTable.parseCursor(cursor);
} catch (Exception e) {
Log.e("Reading sharing pic", e.getMessage());
} finally { } finally {
if (cursor != null) if (cursor != null)
cursor.close(); cursor.close();
@ -523,7 +573,7 @@ public class DAO {
ret = Db.ItemsTable.parseCursor(cursor); ret = Db.ItemsTable.parseCursor(cursor);
} }
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Find item", e.getMessage());
} finally { } finally {
if (cursor != null) if (cursor != null)
cursor.close(); cursor.close();
@ -564,12 +614,8 @@ public class DAO {
if (cursor.moveToNext()) { if (cursor.moveToNext()) {
ret = Db.ItemsTable.parseCursor(cursor); ret = Db.ItemsTable.parseCursor(cursor);
} }
} catch (SQLiteException e) {
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
Log.e("Read item", e.getMessage());
//TODO write to log here
} finally { } finally {
if (cursor != null) if (cursor != null)
cursor.close(); cursor.close();
@ -610,12 +656,8 @@ public class DAO {
if (cursor.moveToNext()) { if (cursor.moveToNext()) {
ret = Db.ItemsTable.parseCursor(cursor); ret = Db.ItemsTable.parseCursor(cursor);
} }
} catch (SQLiteException e) {
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
Log.e("Read item", e.getMessage());
//TODO write to log here
} finally { } finally {
if (cursor != null) if (cursor != null)
cursor.close(); cursor.close();
@ -659,16 +701,10 @@ public class DAO {
cursor = db.rawQuery(query, new String[]{String.valueOf(setId)}); cursor = db.rawQuery(query, new String[]{String.valueOf(setId)});
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
item = Db.ItemsTable.parseCursor(cursor); item = Db.ItemsTable.parseCursor(cursor);
// if (!packed && item.isPendingRemoval())
// continue;
ret.add(item); ret.add(item);
} }
} catch (SQLiteException e) {
//TODO write to log here
ret = null;
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Read items", e.getMessage());
ret = null; ret = null;
} finally { } finally {
if (cursor != null) if (cursor != null)
@ -679,37 +715,6 @@ public class DAO {
return ret; return ret;
} }
private List<Item> readItemsLike(String like) {
List<Item> ret = new ArrayList<>(256);
Cursor cursor = null;
SQLiteDatabase db = null;
Item item;
String query = String.format("SELECT * FROM %s WHERE %s LIKE %s",
Db.ItemsTable.TABLE_NAME,
Db.ItemsTable.COLUMN_NAME,
'\''+like+'%'+'\'');
try {
db = getReadDB();
cursor = db.rawQuery(query, null);
while (cursor.moveToNext()) {
item = Db.ItemsTable.parseCursor(cursor);
ret.add(item);
}
} catch (SQLiteException e) {
e.toString();
//TODO write to log here
} catch (Exception e) {
//TODO write to log here
} finally {
if (cursor != null)
cursor.close();
if (db != null)
db.close();
}
return ret;
}
private List<Item> readItemsLike(String like, int setId, boolean packed) { private List<Item> readItemsLike(String like, int setId, boolean packed) {
List<Item> ret = new ArrayList<>(256); List<Item> ret = new ArrayList<>(256);
Cursor cursor = null; Cursor cursor = null;
@ -746,15 +751,10 @@ public class DAO {
cursor = db.rawQuery(query, new String[]{String.valueOf(setId)}); cursor = db.rawQuery(query, new String[]{String.valueOf(setId)});
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
item = Db.ItemsTable.parseCursor(cursor); item = Db.ItemsTable.parseCursor(cursor);
// if (!packed && item.isPendingRemoval())
// continue;
ret.add(item); ret.add(item);
} }
} catch (SQLiteException e) {
//TODO write to log here
ret = null;
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Read items like", e.getMessage());
ret = null; ret = null;
} finally { } finally {
if (cursor != null) if (cursor != null)
@ -792,11 +792,8 @@ public class DAO {
item.InList = true; item.InList = true;
ret.add(item); ret.add(item);
} }
} catch (SQLiteException e) {
e.toString();
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Read items like", e.getMessage());
} finally { } finally {
if (cursor != null) if (cursor != null)
cursor.close(); cursor.close();
@ -823,11 +820,8 @@ public class DAO {
category = Db.CategoriesTable.parseCursor(cursor); category = Db.CategoriesTable.parseCursor(cursor);
ret.put(category.getId(), category); ret.put(category.getId(), category);
} }
} catch (SQLiteException e) {
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Read categories", e.getMessage());
} finally { } finally {
if (cursor != null) if (cursor != null)
cursor.close(); cursor.close();
@ -861,6 +855,8 @@ public class DAO {
cursor = db.rawQuery(query, null); cursor = db.rawQuery(query, null);
if (cursor.moveToNext()) if (cursor.moveToNext())
ret = Db.SetsTable.parseCursor(cursor); ret = Db.SetsTable.parseCursor(cursor);
} catch (Exception e) {
Log.e("Read set", e.getMessage());
} finally { } finally {
if (cursor != null) if (cursor != null)
cursor.close(); cursor.close();
@ -884,11 +880,8 @@ public class DAO {
ret.add(set); ret.add(set);
} }
Collections.sort(ret); Collections.sort(ret);
} catch (SQLiteException e) {
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Read sets", e.getMessage());
} finally { } finally {
if (cursor != null) if (cursor != null)
cursor.close(); cursor.close();
@ -911,11 +904,37 @@ public class DAO {
ret = db.update(Db.ItemsTable.TABLE_NAME, values, "_id = ?", ret = db.update(Db.ItemsTable.TABLE_NAME, values, "_id = ?",
new String[]{String.valueOf(id)}); new String[]{String.valueOf(id)});
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (SQLiteException e) {
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Update local pic", e.getMessage());
} finally {
if (db != null) {
db.endTransaction();
db.close();
}
}
return ret;
}
private int updateSharingPicLocal(int id, String picPath, String picThumbPath) {
int ret = 0;
SQLiteDatabase db = null;
ContentValues values;
if (picPath == null && picThumbPath == null)
return ret;
try {
db = getWriteDB();
db.beginTransaction();
values = new ContentValues();
if (picPath != null)
values.put(Db.SharingPicsTable.COLUMN_PHOTO_LOCAL, picPath);
if (picThumbPath != null)
values.put(Db.SharingPicsTable.COLUMN_PHOTO_THUMB_LOCAL, picThumbPath);
ret = db.update(Db.SharingPicsTable.TABLE_NAME, values, "_id = ?",
new String[]{String.valueOf(id)});
db.setTransactionSuccessful();
} catch (Exception e) {
Log.e("Update sharing pic path", e.getMessage());
ret = -1;
} finally { } finally {
if (db != null) { if (db != null) {
db.endTransaction(); db.endTransaction();
@ -940,11 +959,8 @@ public class DAO {
new String[]{String.valueOf(set.getId())}); new String[]{String.valueOf(set.getId())});
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (SQLiteException e) {
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Update sets order", e.getMessage());
} finally { } finally {
if (db != null) { if (db != null) {
db.endTransaction(); db.endTransaction();
@ -986,10 +1002,8 @@ public class DAO {
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (SQLiteException e) {
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Update pending removal", e.getMessage());
} finally { } finally {
if (db != null) { if (db != null) {
db.endTransaction(); db.endTransaction();
@ -1032,10 +1046,8 @@ public class DAO {
new String[]{String.valueOf(setId)}); new String[]{String.valueOf(setId)});
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (SQLiteException e) {
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Update item deleted", e.getMessage());
} finally { } finally {
if (db != null) { if (db != null) {
db.endTransaction(); db.endTransaction();
@ -1064,11 +1076,8 @@ public class DAO {
new String[]{String.valueOf(setId)}); new String[]{String.valueOf(setId)});
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (SQLiteException e) {
//TODO write to log here
ret = -1;
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Update set active", e.getMessage());
ret = -1; ret = -1;
} finally { } finally {
if (db != null) { if (db != null) {
@ -1093,12 +1102,9 @@ public class DAO {
Db.SetItemsTable.COLUMN_PENDING_REMOVAL), Db.SetItemsTable.COLUMN_PENDING_REMOVAL),
new String[]{String.valueOf(setId), "1"}); new String[]{String.valueOf(setId), "1"});
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (SQLiteException e) {
ret = -1;
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
ret = -1; ret = -1;
//TODO write to log here Log.e("Clean packed", e.getMessage());
} finally { } finally {
if (db != null) { if (db != null) {
db.endTransaction(); db.endTransaction();
@ -1131,12 +1137,8 @@ public class DAO {
new String[]{String.valueOf(setId)}); new String[]{String.valueOf(setId)});
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (SQLiteException e) {
//TODO write to log here
ret = -1;
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Update item packed", e.getMessage());
ret = -1; ret = -1;
} finally { } finally {
if (db != null) { if (db != null) {
@ -1184,10 +1186,8 @@ public class DAO {
new String[]{String.valueOf(setId)}); new String[]{String.valueOf(setId)});
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (SQLiteException e) {
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Update item packed", e.getMessage());
} finally { } finally {
if (db != null) { if (db != null) {
db.endTransaction(); db.endTransaction();
@ -1228,11 +1228,8 @@ public class DAO {
String.format("%s = ? AND %s = ?", Db.SetItemsTable.COLUMN_SET, Db.SetItemsTable.COLUMN_USER_DEFINED), String.format("%s = ? AND %s = ?", Db.SetItemsTable.COLUMN_SET, Db.SetItemsTable.COLUMN_USER_DEFINED),
new String[]{String.valueOf(setId), String.valueOf(1)}); new String[]{String.valueOf(setId), String.valueOf(1)});
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (SQLiteException e) {
//TODO write to log here
ret = -1;
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Restore defaults", e.getMessage());
ret = -1; ret = -1;
} finally { } finally {
if (db != null) { if (db != null) {
@ -1259,11 +1256,8 @@ public class DAO {
new String[]{String.valueOf(set.getId())}); new String[]{String.valueOf(set.getId())});
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (SQLiteException e) {
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Update set names", e.getMessage());
} finally { } finally {
if (db != null) { if (db != null) {
db.endTransaction(); db.endTransaction();
@ -1289,11 +1283,8 @@ public class DAO {
new String[]{String.valueOf(category.getId())}); new String[]{String.valueOf(category.getId())});
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (SQLiteException e) {
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Update category names", e.getMessage());
} finally { } finally {
if (db != null) { if (db != null) {
db.endTransaction(); db.endTransaction();
@ -1320,11 +1311,8 @@ public class DAO {
new String[]{String.valueOf(item.getId())}); new String[]{String.valueOf(item.getId())});
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (SQLiteException e) {
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Update item names", e.getMessage());
} finally { } finally {
if (db != null) { if (db != null) {
db.endTransaction(); db.endTransaction();
@ -1351,11 +1339,8 @@ public class DAO {
new String[]{String.valueOf(id)}); new String[]{String.valueOf(id)});
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (SQLiteException e) {
//TODO write to log here
} catch (Exception e) { } catch (Exception e) {
//TODO write to log here Log.e("Update log locale", e.getMessage());
} finally { } finally {
if (db != null) { if (db != null) {
db.endTransaction(); db.endTransaction();
@ -1370,27 +1355,6 @@ public class DAO {
//region Task classes //region Task classes
// MY LIST CLASS
private class MyListTask implements Runnable {
int currentCommand;
int priority;
public MyListTask(int command, int priority) {
this.currentCommand = command;
this.priority = priority;
}
@Override
public void run() {
android.os.Process.setThreadPriority(priority);
Message message = Message.obtain();
switch (currentCommand) {
}
handler.sendMessage(message);
}
}
// ITEM CLASS // ITEM CLASS
private class ItemTask implements Runnable { private class ItemTask implements Runnable {
int currentCommand; int currentCommand;
@ -1458,6 +1422,12 @@ public class DAO {
message.what = Event.ITEM_INSERTED; message.what = Event.ITEM_INSERTED;
message.arg1 = setId; message.arg1 = setId;
message.arg2 = item.getId(); message.arg2 = item.getId();
AppRater.updateSharedPreferences(1);
if (AppRater.checkRatePrompt()) {
Message rateEvent = Message.obtain();
rateEvent.what = Event.NEED_TO_RATE_NOW;
handler.sendMessage(rateEvent);
}
} }
} else { } else {
message.what = Event.ITEM_INSERT_ERROR; message.what = Event.ITEM_INSERT_ERROR;
@ -1689,6 +1659,10 @@ public class DAO {
Response<Timestamp> response3 = api.getTimestamp().execute(); Response<Timestamp> response3 = api.getTimestamp().execute();
insertTimestamp(response3.body()); insertTimestamp(response3.body());
statusCode = response3.code(); statusCode = response3.code();
Response<List<SharingPicture>> response4 = api.getSharingPicture().execute();
insertSharingPic(response4.body().get(0));
statusCode = response4.code();
message.what = Event.SYNC_COMPLETED; message.what = Event.SYNC_COMPLETED;
} }
} }
@ -1703,13 +1677,13 @@ public class DAO {
break; break;
case Command.SYNC_READ_FROM_FILE: case Command.SYNC_READ_FROM_FILE:
try { try {
String sets = readSetsFromFile(); String sets = readSetsFromFile();
String categories = readCategoriesFromFile(); String categories = readCategoriesFromFile();
String items = readItemsFromFile(); String items = readItemsFromFile();
String pic = readSharingPicFromFile();
if (sets != null && categories != null && items != null) { if (sets != null && categories != null && items != null && pic != null) {
Gson gson = new Gson(); Gson gson = new Gson();
Type type = new TypeToken<List<Set>>() { Type type = new TypeToken<List<Set>>() {
}.getType(); }.getType();
@ -1724,6 +1698,14 @@ public class DAO {
List<Item> itemsFromJson = gson.fromJson(items, type); List<Item> itemsFromJson = gson.fromJson(items, type);
insertItems(itemsFromJson); insertItems(itemsFromJson);
insertTimestamp(new Timestamp(1456083374)); insertTimestamp(new Timestamp(1456083374));
type = new TypeToken<List<SharingPicture>>() {
}.getType();
List<SharingPicture> picFromJson = gson.fromJson(pic, type);
if (picFromJson != null) {
for (SharingPicture sharingPicture : picFromJson) {
insertSharingPic(sharingPicture);
}
}
message.what = Event.SYNC_COMPLETED; message.what = Event.SYNC_COMPLETED;
} else { } else {
message.what = Event.SYNC_FAILED; message.what = Event.SYNC_FAILED;
@ -1801,6 +1783,31 @@ public class DAO {
message.what = Event.ITEM_IMAGE_LOAD_ERROR; message.what = Event.ITEM_IMAGE_LOAD_ERROR;
} }
break; break;
case Command.SHARING_GET_PIC:
try {
SharingPicture sharingPicture = readLastSharingPic();
if (sharingPicture != null) {
Bitmap[] ret = null;
Bitmap bitmap1 = loadSharingImage(sharingPicture);
Bitmap bitmap2 = loadSharingThumbImage(sharingPicture);
if (bitmap1 != null || bitmap2 != null) {
ret = new Bitmap[2];
ret[0] = bitmap1;
ret[1] = bitmap2;
message.obj = ret;
message.what = Event.SHARING_PIC_LOADED;
} else
message.what = Event.SHARING_GET_PIC_ERROR;
} else
message.what = Event.SHARING_GET_PIC_ERROR;
} catch (Exception e) {
message.what = Event.SHARING_GET_PIC_ERROR;
}
break;
} }
handler.sendMessage(message); handler.sendMessage(message);
} }
@ -1833,6 +1840,62 @@ public class DAO {
return bitmap; return bitmap;
} }
private Bitmap loadSharingImage(SharingPicture sharingPicture) {
ImageDownloadHelper downloadHelper = new ImageDownloadHelper();
Bitmap bitmap = null;
String filename = null;
if (sharingPicture != null) {
if (!TextUtils.isEmpty(sharingPicture.getPhotoLocal()))
bitmap = BitmapFactory.decodeFile(sharingPicture.getPhotoLocal());
// cannot retrieve, download and save then
if (bitmap == null) { // return it
bitmap = downloadHelper.loadImage(sharingPicture.getPhotoUrl());
if (bitmap != null) {
if (downloadHelper.isExternalStorageWritable()) {
filename = downloadHelper.saveImageExternal("sharing_pic", bitmap);
} else {
filename = downloadHelper.saveImageInternal("sharing_pic", bitmap);
}
updateSharingPicLocal(sharingPicture.getId(), filename, null);
}
}
if (bitmap == null) {
bitmap = BitmapFactory.decodeResource(context.getResources(),
R.drawable.sharing_pic_default);
}
}
return bitmap;
}
private Bitmap loadSharingThumbImage(SharingPicture sharingPicture) {
ImageDownloadHelper downloadHelper = new ImageDownloadHelper();
Bitmap bitmap = null;
String filename = null;
if (sharingPicture != null) {
if (!TextUtils.isEmpty(sharingPicture.getPhotoThumbLocal()))
bitmap = BitmapFactory.decodeFile(sharingPicture.getPhotoThumbLocal());
// cannot retrieve, download and save then
if (bitmap == null) { // return it
bitmap = downloadHelper.loadImage(sharingPicture.getPhotoThumbUrl());
if (bitmap != null) {
if (downloadHelper.isExternalStorageWritable()) {
filename = downloadHelper.saveImageExternal("sharing_pic_thumb", bitmap);
} else {
filename = downloadHelper.saveImageInternal("sharing_pic_thumb", bitmap);
}
updateSharingPicLocal(sharingPicture.getId(), null, filename);
}
}
if (bitmap == null) {
bitmap = BitmapFactory.decodeResource(context.getResources(),
R.drawable.sharing_pic_thumb_default);
}
}
return bitmap;
}
private String readSetsFromFile() { private String readSetsFromFile() {
String sets = null; String sets = null;
try { try {
@ -1877,4 +1940,19 @@ public class DAO {
} }
return items; return items;
} }
private String readSharingPicFromFile() {
String sharingPic = null;
try {
InputStream is = App.getAppContext().getAssets().open("jsons/sharing_photos.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
sharingPic = new String(buffer, "UTF-8");
} catch (IOException ex) {
Log.e("Reading json", ex.getMessage());
}
return sharingPic;
}
} }

View File

@ -13,6 +13,7 @@ import java.util.Locale;
import com.hikapro.backpack.model.entities.Category; import com.hikapro.backpack.model.entities.Category;
import com.hikapro.backpack.model.entities.Item; import com.hikapro.backpack.model.entities.Item;
import com.hikapro.backpack.model.entities.Set; import com.hikapro.backpack.model.entities.Set;
import com.hikapro.backpack.model.entities.SharingPicture;
import com.hikapro.backpack.model.entities.Timestamp; import com.hikapro.backpack.model.entities.Timestamp;
import com.hikapro.backpack.model.entities.UpdateLog; import com.hikapro.backpack.model.entities.UpdateLog;
@ -53,6 +54,51 @@ public class Db {
} }
public abstract static class SharingPicsTable {
public static final String TABLE_NAME = "sharing_pics";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_PHOTO_URL = "photo_url";
public static final String COLUMN_PHOTO_THUMB_URL = "photo_thumb_url";
public static final String COLUMN_PHOTO_LOCAL = "photo_local";
public static final String COLUMN_PHOTO_THUMB_LOCAL = "photo_thumb_local";
public static final String CREATE =
"CREATE TABLE " + TABLE_NAME + " (" +
COLUMN_ID + " INTEGER PRIMARY KEY, " +
COLUMN_PHOTO_URL + " TEXT, " +
COLUMN_PHOTO_THUMB_URL + " TEXT, " +
COLUMN_PHOTO_LOCAL + " TEXT, " +
COLUMN_PHOTO_THUMB_LOCAL + " TEXT" +
" ); ";
public static ContentValues toContentValues(SharingPicture sharingPicture) {
ContentValues values = new ContentValues();
values.put(COLUMN_ID, sharingPicture.getId());
if (sharingPicture.getPhotoUrl() != null)
values.put(COLUMN_PHOTO_URL, sharingPicture.getPhotoUrl());
if (sharingPicture.getPhotoThumbUrl() != null)
values.put(COLUMN_PHOTO_THUMB_URL, sharingPicture.getPhotoThumbUrl());
if (sharingPicture.getPhotoLocal() != null)
values.put(COLUMN_PHOTO_LOCAL, sharingPicture.getPhotoLocal());
if (sharingPicture.getPhotoThumbLocal() != null)
values.put(COLUMN_PHOTO_THUMB_LOCAL, sharingPicture.getPhotoThumbLocal());
return values;
}
public static SharingPicture parseCursor(Cursor cursor) {
SharingPicture sharingPicture = new SharingPicture();
sharingPicture.setId(cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_ID)));
sharingPicture.setPhotoUrl(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_PHOTO_URL)));
sharingPicture.setPhotoThumbUrl(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_PHOTO_THUMB_URL)));
sharingPicture.setPhotoLocal(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_PHOTO_LOCAL)));
sharingPicture.setPhotoThumbLocal(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_PHOTO_THUMB_LOCAL)));
return sharingPicture;
}
}
public abstract static class ItemsTable { public abstract static class ItemsTable {
public static final String TABLE_NAME = "items"; public static final String TABLE_NAME = "items";
@ -103,9 +149,7 @@ public class Db {
values.put(COLUMN_PHOTO_LOCAL, item.getPhotoLocal()); values.put(COLUMN_PHOTO_LOCAL, item.getPhotoLocal());
values.put(COLUMN_USER_DEFINED, item.isUserDefined()); values.put(COLUMN_USER_DEFINED, item.isUserDefined());
/*
values.put(COLUMN_PHOTO_THUMB_LOCAL, item.getName());
*/
return values; return values;
} }
@ -194,11 +238,7 @@ public class Db {
values.put(COLUMN_PHOTO_THUMBNAIL_URL, set.getPhotoThumbnail()); values.put(COLUMN_PHOTO_THUMBNAIL_URL, set.getPhotoThumbnail());
values.put(COLUMN_LINE_NUMBER, lineNumber); values.put(COLUMN_LINE_NUMBER, lineNumber);
values.put(COLUMN_ACTIVE_QTY, items.size()); values.put(COLUMN_ACTIVE_QTY, items.size());
/*
values.put(COLUMN_PHOTO_LOCAL, "");
values.put(COLUMN_PHOTO_THUMB_LOCAL, "");
values.put(COLUMN_PHOTO_THUMBNAIL_LOCAL, "");
*/
return values; return values;
} }

View File

@ -40,6 +40,7 @@ public class DbHelper extends SQLiteOpenHelper {
db.execSQL(Db.SetsTable.CREATE); db.execSQL(Db.SetsTable.CREATE);
db.execSQL(Db.LogTable.CREATE); db.execSQL(Db.LogTable.CREATE);
db.execSQL(Db.SetItemsTable.CREATE); db.execSQL(Db.SetItemsTable.CREATE);
db.execSQL(Db.SharingPicsTable.CREATE);
if (oldVersion < 2) { if (oldVersion < 2) {
// place the logic here // place the logic here

View File

@ -52,15 +52,9 @@ public interface Event {
int ITEM_REMOVAL_CANCELED = 0x1D; int ITEM_REMOVAL_CANCELED = 0x1D;
int ITEM_READ_COMPLETED = 0x1E; int ITEM_READ_COMPLETED = 0x1E;
int MY_LIST_POST_ERROR = -0x28; int SHARING_GET_PIC_ERROR = -0x28;
int MY_LIST_ITEM_ADD_ERROR = -0x29;
int MY_LIST_ITEM_DELETE_ERROR = -0x2A;
int MY_LIST_CLEAR_ERROR = -0x2B;
int MY_LIST_POSTED = 0x28; int SHARING_PIC_LOADED = 0x28;
int MY_LIST_ITEM_ADDED = 0x29;
int MY_LIST_ITEM_DELETED = 0x2A;
int MY_LIST_CLEARED = 0x2B;
int SYNC_FAILED = -0x3C; int SYNC_FAILED = -0x3C;
int SYNC_NO_CONNECTION = -0x3D; int SYNC_NO_CONNECTION = -0x3D;
@ -68,6 +62,7 @@ public interface Event {
int NOT_IMPLEMENTED = 0x50; int NOT_IMPLEMENTED = 0x50;
int NOT_UNDERSTAND = 0x51; int NOT_UNDERSTAND = 0x51;
int NEED_TO_RATE_NOW = 0x52;
} }

View File

@ -7,6 +7,7 @@ import android.net.Uri;
import android.os.Environment; import android.os.Environment;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -16,6 +17,8 @@ import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import com.hikapro.backpack.App; import com.hikapro.backpack.App;
import com.hikapro.backpack.R;
import com.hikapro.backpack.model.NetworkUtil;
/** /**
* Created by tariel on 04/05/16. * Created by tariel on 04/05/16.
@ -32,6 +35,7 @@ public class ImageDownloadHelper {
public Bitmap loadImage(String netPath) { public Bitmap loadImage(String netPath) {
Bitmap bitmap = null; Bitmap bitmap = null;
if (NetworkUtil.isInternetAvailable()) {
try { try {
URL url = new URL(netPath); URL url = new URL(netPath);
URLConnection conn = url.openConnection(); URLConnection conn = url.openConnection();
@ -43,6 +47,7 @@ public class ImageDownloadHelper {
} catch (Exception ex) { } catch (Exception ex) {
Log.e(IMAGE_DOWNLOAD_TAG, " File cannot be downloaded due to exception."); Log.e(IMAGE_DOWNLOAD_TAG, " File cannot be downloaded due to exception.");
} }
}
return bitmap; return bitmap;
} }

View File

@ -1,15 +0,0 @@
package com.hikapro.backpack.model.dao;
/**
* Created by tariel on 27/04/16.
*/
public class Test {
private static Test ourInstance = new Test();
public static Test getInstance() {
return ourInstance;
}
private Test() {
}
}

View File

@ -174,10 +174,6 @@ public class Item implements Comparable<Item>, Serializable {
@Override @Override
public int compareTo(Item another) { public int compareTo(Item another) {
/*
int cmp = Integer.valueOf(category).compareTo(Integer.valueOf(another.category));
return (cmp != 0 ? cmp : name.compareTo(another.name));
*/
int cmp = Integer.valueOf(category).compareTo(Integer.valueOf(another.category)); int cmp = Integer.valueOf(category).compareTo(Integer.valueOf(another.category));
if (cmp != 0) if (cmp != 0)
return cmp; return cmp;

View File

@ -0,0 +1,83 @@
package com.hikapro.backpack.model.entities;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* Created by tariel on 24/07/16.
*/
public class SharingPicture {
@SerializedName("id")
@Expose
private int id;
@SerializedName("photo")
@Expose
private String photoUrl;
@SerializedName("photo_thumb")
@Expose
private String photoThumbUrl;
private String photoLocal;
private String photoThumbLocal;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPhotoUrl() {
return photoUrl;
}
public void setPhotoUrl(String photoUrl) {
this.photoUrl = photoUrl;
}
public String getPhotoThumbUrl() {
return photoThumbUrl;
}
public void setPhotoThumbUrl(String photoThumbUrl) {
this.photoThumbUrl = photoThumbUrl;
}
public String getPhotoLocal() {
return photoLocal;
}
public void setPhotoLocal(String photoLocal) {
this.photoLocal = photoLocal;
}
public String getPhotoThumbLocal() {
return photoThumbLocal;
}
public void setPhotoThumbLocal(String photoThumbLocal) {
this.photoThumbLocal = photoThumbLocal;
}
@Override
public int hashCode() {
return 31 * id;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SharingPicture that = (SharingPicture) o;
if (id != that.id)
return false;
return true;
}
}

View File

@ -19,6 +19,4 @@ public class Timestamp {
this.timestamp = value; this.timestamp = value;
} }
} }

View File

@ -118,34 +118,24 @@ public class AddPresenter implements Presenter.Add {
cancelButton = (Button) custActionBarView.findViewById(R.id.action_add_cancel); cancelButton = (Button) custActionBarView.findViewById(R.id.action_add_cancel);
saveButton = (Button) custActionBarView.findViewById(R.id.action_add_save); saveButton = (Button) custActionBarView.findViewById(R.id.action_add_save);
cancelButton.setOnClickListener(new ActionBarButtonClickListener()); android.view.View.OnClickListener listener = new ActionBarButtonClickListener();
saveButton.setOnClickListener(new ActionBarButtonClickListener()); cancelButton.setOnClickListener(listener);
saveButton.setOnClickListener(listener);
} }
} }
searchView = (SearchView) view.findViewById(R.id.add_search); searchView = (SearchView) view.findViewById(R.id.add_search);
searchView.setIconified(false); searchView.setIconified(false);
searchView.setIconifiedByDefault(false); searchView.setIconifiedByDefault(false);
searchView.setQueryHint("Enter a new item name"); searchView.setQueryHint(getActivityContext().getResources().getString(R.string.search_hint_add));
searchView.setSubmitButtonEnabled(false); searchView.setSubmitButtonEnabled(false);
searchView.setBottom(20); searchView.setBottom(20);
/*
Drawable d = getActivityContext().getResources().getDrawable( R.drawable.search_divider );
searchView.setDividerDrawable(d);*/
int magId = searchView.getContext().getResources().getIdentifier("android:id/search_mag_icon", null, null); int magId = searchView.getContext().getResources().getIdentifier("android:id/search_mag_icon", null, null);
ImageView magImage = (ImageView) searchView.findViewById(magId); ImageView magImage = (ImageView) searchView.findViewById(magId);
magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0)); magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
searchView.setMinimumHeight(40); searchView.setMinimumHeight(40);
searchView.setOnQueryTextListener(new SearchTextListener()); searchView.setOnQueryTextListener(new SearchTextListener());
/*
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
// Getting the 'search_plate' LinearLayout.
android.view.View searchPlate = searchView.findViewById(searchPlateId);
// Setting background of 'search_plate' to earlier defined drawable.
searchPlate.setBackgroundResource(R.drawable.search_divider);
*/
return view; return view;
} }
@ -207,11 +197,11 @@ public class AddPresenter implements Presenter.Add {
private boolean checkUserInput() { private boolean checkUserInput() {
if (!canSave) { if (!canSave) {
if (searchView.getQuery().length() == 0) if (searchView.getQuery().length() == 0)
Toast.makeText(getActivityContext(), "Please, enter a name", Toast.LENGTH_SHORT).show(); Toast.makeText(getActivityContext(), R.string.enter_name, Toast.LENGTH_SHORT).show();
else if (categoryContainerMain.getVisibility() == android.view.View.VISIBLE) else if (categoryContainerMain.getVisibility() == android.view.View.VISIBLE)
Toast.makeText(getActivityContext(), "Please, select a category", Toast.LENGTH_SHORT).show(); Toast.makeText(getActivityContext(), R.string.select_category, Toast.LENGTH_SHORT).show();
else else
Toast.makeText(getActivityContext(), "Already in List!", Toast.LENGTH_SHORT).show(); Toast.makeText(getActivityContext(), R.string.already_in_list2, Toast.LENGTH_SHORT).show();
return false; return false;
} }
return true; return true;
@ -269,7 +259,6 @@ public class AddPresenter implements Presenter.Add {
} }
currentCategoryButton = (Button) v; currentCategoryButton = (Button) v;
Toast.makeText(getActivityContext(), "Id " + currentCategoryButton.getId(), Toast.LENGTH_SHORT).show();
setSaveButtonAccess(); setSaveButtonAccess();
} }
} }
@ -281,7 +270,6 @@ public class AddPresenter implements Presenter.Add {
switch (v.getId()) switch (v.getId())
{ {
case R.id.action_add_cancel : case R.id.action_add_cancel :
Toast.makeText(getActivityContext(), "Cancel", Toast.LENGTH_SHORT).show();
searchView.clearFocus(); searchView.clearFocus();
if (fragment != null) if (fragment != null)
fragment.getFragmentManager().popBackStack(); fragment.getFragmentManager().popBackStack();

View File

@ -2,15 +2,19 @@ package com.hikapro.backpack.presenter;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -19,13 +23,11 @@ import java.lang.ref.WeakReference;
import com.hikapro.backpack.R; import com.hikapro.backpack.R;
import com.hikapro.backpack.model.Model; import com.hikapro.backpack.model.Model;
import com.hikapro.backpack.model.entities.Item;
import com.hikapro.backpack.model.entities.Set; import com.hikapro.backpack.model.entities.Set;
import com.hikapro.backpack.presenter.adapters.helper.AppRater;
import com.hikapro.backpack.presenter.adapters.helper.Util; import com.hikapro.backpack.presenter.adapters.helper.Util;
import com.hikapro.backpack.presenter.adapters.helper.items.DividerDecoration;
import com.hikapro.backpack.presenter.adapters.ItemListAdapter; import com.hikapro.backpack.presenter.adapters.ItemListAdapter;
import com.hikapro.backpack.presenter.adapters.helper.items.DividerDecoration2; import com.hikapro.backpack.presenter.adapters.helper.items.DividerDecoration2;
import com.hikapro.backpack.presenter.adapters.helper.items.ItemSwipeCallback;
import com.hikapro.backpack.presenter.adapters.helper.items.StickyHeaderDecoration; import com.hikapro.backpack.presenter.adapters.helper.items.StickyHeaderDecoration;
import com.hikapro.backpack.view.View; import com.hikapro.backpack.view.View;
@ -51,8 +53,6 @@ public class ItemListPresenter implements Presenter.ItemList {
adapter.setHasStableIds(true); adapter.setHasStableIds(true);
} }
// life cycle -->
@Override @Override
public void onDestroy(boolean isChangingConfiguration) { public void onDestroy(boolean isChangingConfiguration) {
view = null; view = null;
@ -64,12 +64,12 @@ public class ItemListPresenter implements Presenter.ItemList {
@Override @Override
public android.view.View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public android.view.View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// TODO check nn
if (savedInstanceState != null) if (savedInstanceState != null)
set = (Set) savedInstanceState.getSerializable(BUNDLE_SET_LIST_KEY); set = (Set) savedInstanceState.getSerializable(BUNDLE_SET_LIST_KEY);
else else
set = getView().getSet(); set = getView().getSet();
android.view.View view = inflater.inflate(R.layout.fragment_item_list, container, false); android.view.View view = inflater.inflate(R.layout.fragment_item_list, container, false);
LinearLayoutManager llm = new LinearLayoutManager(getActivityContext()); LinearLayoutManager llm = new LinearLayoutManager(getActivityContext());
recycler = (RecyclerView) view.findViewById(R.id.items_recycler); recycler = (RecyclerView) view.findViewById(R.id.items_recycler);
recycler.setLayoutManager(llm); recycler.setLayoutManager(llm);
@ -88,6 +88,7 @@ public class ItemListPresenter implements Presenter.ItemList {
}); });
recycler.setHasFixedSize(true); recycler.setHasFixedSize(true);
model.executeQuery(); model.executeQuery();
footer = (LinearLayout) view.findViewById(R.id.item_list_footer); footer = (LinearLayout) view.findViewById(R.id.item_list_footer);
packedCount = (TextView) footer.findViewById(R.id.footer_packed_count); packedCount = (TextView) footer.findViewById(R.id.footer_packed_count);
showPacked = (TextView) footer.findViewById(R.id.open_packed); showPacked = (TextView) footer.findViewById(R.id.open_packed);
@ -97,6 +98,15 @@ public class ItemListPresenter implements Presenter.ItemList {
showPackedItems(); showPackedItems();
} }
}); });
if (set != null) {
android.view.View con = view.findViewById(R.id.item_list_container);
applyBackground(con, set.getId());
}
return view;
}
private void setupActionBar() {
Activity activity = (Activity) getActivityContext(); Activity activity = (Activity) getActivityContext();
if (activity != null) { if (activity != null) {
activity.invalidateOptionsMenu(); activity.invalidateOptionsMenu();
@ -110,19 +120,14 @@ public class ItemListPresenter implements Presenter.ItemList {
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
} }
} }
return view;
} }
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
if (set != null) if (set != null)
outState.putSerializable(BUNDLE_SET_LIST_KEY, set); outState.putSerializable(BUNDLE_SET_LIST_KEY, set);
} }
// life cycle <--
// process -->
@Override @Override
public void notifyDataSetChanged() { public void notifyDataSetChanged() {
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
@ -152,20 +157,25 @@ public class ItemListPresenter implements Presenter.ItemList {
} else { } else {
footer.setVisibility(android.view.View.GONE); footer.setVisibility(android.view.View.GONE);
} }
} }
private void showPackedItems () { private void showPackedItems () {
getView().showPackedItems(set); getView().showPackedItems(set);
rememberPosition();
}
private void rememberPosition() {
LinearLayoutManager llm = (LinearLayoutManager)recycler.getLayoutManager();
int pos = llm.findFirstVisibleItemPosition();
model.setLastVisiblePosition(pos);
Log.i("Last position remember", String.valueOf(pos));
} }
@Override @Override
public void showDetails(int position) { public void showDetails(int position) {
getView().showItemDetail(getCurrentSet().getId(), model, position); getView().showItemDetail(getCurrentSet().getId(), model, position);
rememberPosition();
} }
// process <--
// other impl -->
@Override @Override
public void setView(View.ItemList view) { public void setView(View.ItemList view) {
@ -205,8 +215,6 @@ public class ItemListPresenter implements Presenter.ItemList {
Toast.makeText(getView().getAppContext(), message, Toast.LENGTH_SHORT).show(); Toast.makeText(getView().getAppContext(), message, Toast.LENGTH_SHORT).show();
} }
// other impl <--
protected View.ItemList getView() throws NullPointerException { protected View.ItemList getView() throws NullPointerException {
if ( view != null ) if ( view != null )
return view.get(); return view.get();
@ -232,37 +240,102 @@ public class ItemListPresenter implements Presenter.ItemList {
@Override @Override
public void restore(final int setId) { public void restore(final int setId) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivityContext(), AlertDialog.THEME_HOLO_DARK);
builder.setMessage(R.string.dlg_restore_txt) final Dialog dialog = new Dialog(getActivityContext());
.setTitle(R.string.dlg_restore_header);
builder.setPositiveButton(R.string.ok_button, new DialogInterface.OnClickListener() { dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
public void onClick(DialogInterface dialog, int id) { dialog.setContentView(R.layout.dialog_confirm);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Button cancel = (Button) dialog.findViewById(R.id.button_cancel);
Button ok = (Button) dialog.findViewById(R.id.button_ok);
cancel.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
try {
dialog.dismiss();
} catch (Exception e) {
}
}
});
ok.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
model.restoreSet(setId); model.restoreSet(setId);
dialog.dismiss();
} }
}); });
builder.setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
AlertDialog dialog = builder.create();
dialog.show(); dialog.show();
}
//Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE); public void applyBackground(android.view.View view, int setId) {
//button.setBackgroundColor(Color.GREEN);
/*
Drawable d = button.getBackground();
PorterDuffColorFilter filter = new PorterDuffColorFilter(Color.GREEN, PorterDuff.Mode.SRC_ATOP);
d.setColorFilter(filter);*/
//button = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
//button.setBackgroundColor(Color.GRAY);
/*
d = button.getBackground();
filter = new PorterDuffColorFilter(Color.GRAY, PorterDuff.Mode.SRC_ATOP);
d.setColorFilter(filter);*/
Drawable drawable = null;
switch (setId) {
case 1:
drawable = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_item_list_1);
break;
case 2:
drawable = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_item_list_2);
break;
case 3:
drawable = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_item_list_3);
break;
case 4:
drawable = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_item_list_4);
break;
case 5:
drawable = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_item_list_5);
break;
case 6:
drawable = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_item_list_6);
break;
case 7:
// nothing
break;
case 8:
drawable = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_item_list_8);
break;
case 9:
// nothing
break;
case 10:
drawable = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_item_list_10);
break;
case 11:
// nothing
break;
case 12:
// nothing
break;
case 13:
// nothing
break;
case 14:
drawable = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_item_list_14);
break;
default:
} }
if (drawable != null)
view.setBackground(drawable);
else
view.setBackgroundColor(ContextCompat.getColor(view.getContext(), R.color.colorListBackground));
}
@Override
public void onResume() {
recycler.scrollToPosition(model.getLastVisiblePosition());
setupActionBar();
}
@Override
public void showRateDialog() {
AppRater.showRateDialog(getActivityContext());
}
} }

View File

@ -60,9 +60,8 @@ public class PackedListPresenter extends ItemListPresenter {
} }
}); });
recycler.setHasFixedSize(true); recycler.setHasFixedSize(true);
model.executeQuery(); model.executeQuery();
recycler.scrollToPosition(model.getLastVisiblePosition());
backToList = (TextView) view.findViewById(R.id.back_to_list); backToList = (TextView) view.findViewById(R.id.back_to_list);
packedCount = (TextView) view.findViewById(R.id.header_packed_count); packedCount = (TextView) view.findViewById(R.id.header_packed_count);
unpackButton = (Button) view.findViewById(R.id.unpack_button); unpackButton = (Button) view.findViewById(R.id.unpack_button);

View File

@ -60,6 +60,8 @@ public interface Presenter {
void filter(String query); void filter(String query);
void unpack(int setId); void unpack(int setId);
void restore(int setId); void restore(int setId);
void onResume();
void showRateDialog();
} }
interface ItemDetail extends Base { interface ItemDetail extends Base {
@ -78,6 +80,7 @@ public interface Presenter {
interface Share extends Base { interface Share extends Base {
void setView(View.Share view); void setView(View.Share view);
void setModel(Model.Share model); void setModel(Model.Share model);
void notifyDataSetChanged();
Model.Share getModel(); Model.Share getModel();
void onDestroy(boolean isChangingConfiguration); void onDestroy(boolean isChangingConfiguration);
android.view.View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); android.view.View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);

View File

@ -45,9 +45,6 @@ public class SetListPresenter implements Presenter.SetList {
this.adapter = new SetListAdapter(this); this.adapter = new SetListAdapter(this);
} }
// life cycle -->
//GLM_add_resources_SetList //GLM_add_resources_SetList
@Override @Override
public void onItemDismiss(int position) { public void onItemDismiss(int position) {
@ -85,7 +82,9 @@ public class SetListPresenter implements Presenter.SetList {
setRecycler.setLayoutManager(llm); setRecycler.setLayoutManager(llm);
setRecycler.setAdapter(adapter); setRecycler.setAdapter(adapter);
setRecycler.setItemAnimator(new DefaultItemAnimator()); setRecycler.setItemAnimator(new DefaultItemAnimator());
setRecycler.setHasFixedSize(true);
model.executeQuery(); model.executeQuery();
setRecycler.scrollToPosition(model.getLastVisiblePosition());
//GLM_add_resources_SetList //GLM_add_resources_SetList
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(adapter); ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(adapter);
@ -98,19 +97,11 @@ public class SetListPresenter implements Presenter.SetList {
return view; return view;
} }
// life cycle <--
// process -->
@Override @Override
public void notifyDataSetChanged() { public void notifyDataSetChanged() {
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
// process <--
// other impl -->
@Override @Override
public Context getAppContext() { public Context getAppContext() {
try { try {
@ -142,8 +133,6 @@ public class SetListPresenter implements Presenter.SetList {
return model; return model;
} }
// other impl <--
private View.SetList getView() throws NullPointerException { private View.SetList getView() throws NullPointerException {
if ( view != null ) if ( view != null )
return view.get(); return view.get();
@ -170,8 +159,11 @@ public class SetListPresenter implements Presenter.SetList {
} }
public void showItemList(Set set) { public void showItemList(Set set) {
if (getView() != null) if (getView() != null) {
getView().showItemList(set); getView().showItemList(set);
LinearLayoutManager llm = (LinearLayoutManager)setRecycler.getLayoutManager();
model.setLastVisiblePosition(llm.findFirstVisibleItemPosition());
}
else else
Toast.makeText(getActivityContext(), "There is no view in presenter", Toast.LENGTH_SHORT).show(); Toast.makeText(getActivityContext(), "There is no view in presenter", Toast.LENGTH_SHORT).show();
} }

View File

@ -1,19 +1,32 @@
package com.hikapro.backpack.presenter; package com.hikapro.backpack.presenter;
import android.app.ActionBar;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog;
import android.app.Fragment;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.facebook.CallbackManager; import com.facebook.CallbackManager;
import com.facebook.FacebookCallback; import com.facebook.FacebookCallback;
import com.facebook.FacebookException; import com.facebook.FacebookException;
import com.facebook.FacebookSdk; import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.share.Sharer; import com.facebook.share.Sharer;
import com.facebook.share.model.ShareHashtag; import com.facebook.share.model.ShareHashtag;
import com.facebook.share.model.ShareLinkContent; import com.facebook.share.model.ShareLinkContent;
@ -22,6 +35,13 @@ import com.hikapro.backpack.R;
import com.hikapro.backpack.model.Model; import com.hikapro.backpack.model.Model;
import com.hikapro.backpack.view.View; import com.hikapro.backpack.view.View;
import org.brickred.socialauth.Profile;
import org.brickred.socialauth.android.DialogListener;
import org.brickred.socialauth.android.SocialAuthAdapter;
import org.brickred.socialauth.android.SocialAuthError;
import org.brickred.socialauth.android.SocialAuthListener;
import java.io.File;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
/** /**
@ -34,6 +54,16 @@ public class SharePresenter implements Presenter.Share {
private Button facebookButton; private Button facebookButton;
private Button twitterButton; private Button twitterButton;
private Button cancelButton;
private ImageView sharingImage;
private TextView twitterLogin;
private Profile twitterProfile;
private ViewGroup progress;
private boolean canPost;
private boolean showError;
protected SocialAuthAdapter socialAuthAdapter;
private WeakReference<View.Share> view; private WeakReference<View.Share> view;
private Model.Share model; private Model.Share model;
@ -67,6 +97,19 @@ public class SharePresenter implements Presenter.Share {
this.model = model; this.model = model;
} }
@Override
public void notifyDataSetChanged() {
Bitmap [] pics = model.getSharingPics();
if (pics != null && pics[1] != null && pics[0] != null) {
canPost = true;
sharingImage.setImageBitmap(pics[0]);
} else {
showError = true;
canPost = true;
}
setVisibility();
}
@Override @Override
public Model.Share getModel() { public Model.Share getModel() {
return model; return model;
@ -92,44 +135,95 @@ public class SharePresenter implements Presenter.Share {
shareDialog = new ShareDialog((Activity) getActivityContext()); shareDialog = new ShareDialog((Activity) getActivityContext());
facebookButton = (Button) v.findViewById(R.id.facebook_share_button); facebookButton = (Button) v.findViewById(R.id.facebook_share_button);
twitterButton = (Button) v.findViewById(R.id.twitter_share_button); twitterButton = (Button) v.findViewById(R.id.twitter_share_button);
progress = (ViewGroup) v.findViewById(R.id.share_progress_container);
sharingImage = (ImageView) v.findViewById(R.id.share_image_view);
model.executeQuery();
shareDialog.registerCallback(callbackManager, new shareDialog.registerCallback(callbackManager, new
FacebookCallback<Sharer.Result>() { FacebookCallback<Sharer.Result>() {
@Override @Override
public void onSuccess(Sharer.Result result) {} public void onSuccess(Sharer.Result result) {
Toast.makeText(getActivityContext(), R.string.fb_posted,
Toast.LENGTH_SHORT).show();
}
@Override @Override
public void onCancel() {} public void onCancel() {}
@Override @Override
public void onError(FacebookException error) {} public void onError(FacebookException error) {
Toast.makeText(getActivityContext(), R.string.fb_error,
Toast.LENGTH_SHORT).show();
Log.e("Share", "Facebook error", error);
}
}); });
facebookButton.setOnClickListener(new android.view.View.OnClickListener() { facebookButton.setOnClickListener(new android.view.View.OnClickListener() {
@Override @Override
public void onClick(android.view.View v) { public void onClick(android.view.View v) {
if (ShareDialog.canShow(ShareLinkContent.class)) { if (ShareDialog.canShow(ShareLinkContent.class)) {
try {
Context context = getAppContext();
ShareLinkContent linkContent = new ShareLinkContent.Builder() ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Test Pack With Me app") .setContentTitle(context.getString(R.string.facebook_sharing_header))
.setContentDescription("Test of facebook integration") .setContentDescription(context.getString(R.string.facebook_sharing_txt))
.setContentUrl(Uri.parse("http://developers.facebook.com/android")) .setContentUrl(Uri.parse(context.getString(R.string.facebook_url)))
.setShareHashtag(new ShareHashtag.Builder() .setShareHashtag(new ShareHashtag.Builder()
.setHashtag("#PackWithMe") .setHashtag("#PackWithMe")
.build()) .build())
.build(); .build();
shareDialog.show(linkContent); shareDialog.show(linkContent);
} catch (Exception e) {
Toast.makeText(getActivityContext(), R.string.fb_error,
Toast.LENGTH_SHORT).show();
Log.e("Sharing", "Facebook error", e);
} }
} }
});
twitterButton.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
Toast.makeText(getActivityContext(), "Not implemented!", Toast.LENGTH_SHORT).show();
} }
}); });
twitterButton.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
if (! canPost )
Toast.makeText(getActivityContext(), R.string.please_wait, Toast.LENGTH_SHORT).show();
else if (showError)
Toast.makeText(getActivityContext(), R.string.cannot_post, Toast.LENGTH_SHORT).show();
else
postToTwitter();
}
});
Activity activity = (Activity) getActivityContext();
if (activity != null) {
ActionBar actionBar = activity.getActionBar();
if (actionBar != null) {
ViewGroup custActionBarView = (ViewGroup) inflater.inflate(R.layout.share_cust_actionbar, null);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setCustomView(custActionBarView);
cancelButton = (Button) custActionBarView.findViewById(R.id.action_share_cancel);
cancelButton.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
Fragment fragment = (Fragment) getView();
if (fragment != null)
fragment.getFragmentManager().popBackStack();
}
});
}
}
twitterLogin = (TextView) v.findViewById(R.id.twitter_login);
setVisibility();
return v; return v;
} }
@ -139,4 +233,171 @@ public class SharePresenter implements Presenter.Share {
else else
throw new NullPointerException("View is unavailable"); throw new NullPointerException("View is unavailable");
} }
private class ResponseListener implements DialogListener {
Bitmap bitmap;
String message;
public ResponseListener(Bitmap bitmap, String message) {
this.bitmap = bitmap;
this.message = message;
}
@Override
public void onComplete(final Bundle values) {
try {
socialAuthAdapter.getUserProfileAsync(new ProfileDataListener());
socialAuthAdapter.uploadImageAsync(message, "PackWithMe.png",
bitmap, 0, new UploadImageListener());
} catch (Exception e) {
Log.e("ShareTwitter", e.getMessage());
}
}
@Override
public void onError(SocialAuthError error) {
Log.d("ShareTwitter", "Authentication Error: " + error.getMessage());
}
@Override
public void onCancel() {
Log.d("ShareTwitter", "Authentication Cancelled");
}
@Override
public void onBack() {
Log.d("ShareTwitter", "Dialog Closed by pressing Back Key");
}
}
private final class UploadImageListener implements SocialAuthListener {
@Override
public void onExecute(String s, Object o) {
Integer status = (Integer) o;
try {
if (status.intValue() == 200 || status.intValue() == 201
|| status.intValue() == 204) {
Toast.makeText(getActivityContext(), R.string.twitter_posted,
Toast.LENGTH_SHORT).show();
Log.d("ShareTwitter", "Posting completed");
} else {
Toast.makeText(getActivityContext(), R.string.twitter_error2,
Toast.LENGTH_SHORT).show();
Log.d("ShareTwitter", "Posting failed");
}
} catch (NullPointerException e) {
Toast.makeText(getActivityContext(), R.string.twitter_error2,
Toast.LENGTH_SHORT).show();
Log.e("ShareTwitter", e.getMessage());
}
}
@Override
public void onError(SocialAuthError e) {
Toast.makeText(getActivityContext(), "Posting to twitter failed!",
Toast.LENGTH_SHORT).show();
Log.e("ShareTwitter", e.getMessage());
}
}
private final class ProfileDataListener implements SocialAuthListener<Profile> {
@Override
public void onExecute(String s, Profile profile) {
twitterProfile = profile;
if (twitterProfile != null && twitterLogin != null) {
twitterLogin.setText(twitterProfile.getDisplayName());
}
}
@Override
public void onError(SocialAuthError socialAuthError) {
}
}
private void setVisibility() {
if (showError) {
progress.setVisibility(android.view.View.GONE);
sharingImage.setVisibility(android.view.View.VISIBLE);
}
else {
progress.setVisibility(canPost ? android.view.View.GONE : android.view.View.VISIBLE);
sharingImage.setVisibility(canPost ? android.view.View.VISIBLE : android.view.View.GONE);
}
}
private void postToTwitter() {
final Dialog dialog = new Dialog(getActivityContext());
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_twitter);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Button cancel = (Button) dialog.findViewById(R.id.button_cancel);
Button post = (Button) dialog.findViewById(R.id.button_post);
final EditText editText = (EditText) dialog.findViewById(R.id.message);
final ImageView imageView = (ImageView) dialog.findViewById(R.id.image_to_post);
final TextView textView = (TextView) dialog.findViewById(R.id.chars_left);
textView.setText(String.valueOf(140 - editText.getText().length()));
if (model.getSharingPics() != null) {
Bitmap sharingBitmap = model.getSharingPics()[1];
if (sharingBitmap != null) {
imageView.setImageBitmap(sharingBitmap);
} else {
Toast.makeText(getActivityContext(), R.string.twitter_error, Toast.LENGTH_SHORT).show();
}
}
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
int left = 140 - s.length();
textView.setText(String.valueOf(left));
}
@Override
public void afterTextChanged(Editable s) {
}
});
cancel.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
try {
dialog.dismiss();
} catch (Exception e) {
}
}
});
post.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
socialAuthAdapter = new SocialAuthAdapter(new ResponseListener(((BitmapDrawable)imageView.getDrawable()).getBitmap(),
editText.getText().toString()));
socialAuthAdapter.addProvider(SocialAuthAdapter.Provider.TWITTER, R.drawable.ic_twitter_icon);
socialAuthAdapter.authorize(getActivityContext(), SocialAuthAdapter.Provider.TWITTER);
dialog.dismiss();
}
});
dialog.show();
}
} }

View File

@ -41,7 +41,7 @@ public class ItemDetailAdapter extends RecyclerView.Adapter<ItemViewHolder> {
public void onBindViewHolder(final ItemViewHolder holder, final int position) { public void onBindViewHolder(final ItemViewHolder holder, final int position) {
final Item item = presenter.getModel().getCurrentItem(); final Item item = presenter.getModel().getCurrentItem();
holder.cb_item.setChecked(item.isPacked()); holder.cb_item.setChecked(item.isPacked());
holder.tv_text.setText(item.getName() + " " + item.getId() + " pos " + position); holder.tv_text.setText(item.getName());
holder.im_info.setVisibility(View.GONE); holder.im_info.setVisibility(View.GONE);
if (item.isPendingRemoval()) { if (item.isPendingRemoval()) {
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

View File

@ -58,7 +58,7 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
final Item item = presenter.getModel().getItemByPosition(position); final Item item = presenter.getModel().getItemByPosition(position);
holder.cb_item.setChecked(checkAll); holder.cb_item.setChecked(checkAll);
holder.tv_text.setText(item.getName() + " " + item.getId() + " pos " + position); holder.tv_text.setText(item.getName());
//holder.tv_text.setTypeface(mainFace); //holder.tv_text.setTypeface(mainFace);
if (item.isPendingRemoval()) { if (item.isPendingRemoval()) {
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

View File

@ -28,7 +28,7 @@ public class PackedListAdapter extends ItemListAdapter {
final Item item = presenter.getModel().getItemByPosition(position); final Item item = presenter.getModel().getItemByPosition(position);
holder.cb_item.setChecked(checkAll); holder.cb_item.setChecked(checkAll);
holder.tv_text.setText(item.getName() + " " + item.getId() + " pos " + position); holder.tv_text.setText(item.getName());
if (item.isPendingRemoval()) { if (item.isPendingRemoval()) {
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
holder.cb_item.setVisibility(View.GONE); holder.cb_item.setVisibility(View.GONE);
@ -156,11 +156,8 @@ public class PackedListAdapter extends ItemListAdapter {
@Override @Override
public void remove(Item item) { public void remove(Item item) {
if (item.isPendingRemoval()) {
presenter.getModel().unpackItem(item); presenter.getModel().unpackItem(item);
presenter.getModel().remove(item); presenter.getModel().remove(item);
}
else
presenter.getModel().pendingRemove(item); presenter.getModel().pendingRemove(item);
} }
@ -169,4 +166,9 @@ public class PackedListAdapter extends ItemListAdapter {
presenter.getModel().pendingRemove(item); presenter.getModel().pendingRemove(item);
} }
@Override
public void pack(Item item) {
item.setPacked(false);
super.pack(item);
}
} }

View File

@ -1,6 +1,8 @@
package com.hikapro.backpack.presenter.adapters; package com.hikapro.backpack.presenter.adapters;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -37,7 +39,6 @@ public class SetListAdapter extends RecyclerView.Adapter<SetViewHolder> impleme
else else
this.rightBracket = ""; this.rightBracket = "";
} }
holder.textView.setText(set.getName() + " " + rightBracket); holder.textView.setText(set.getName() + " " + rightBracket);
holder.textView.setTypeface(App.getMainFace()); holder.textView.setTypeface(App.getMainFace());
String info = String.format("%s %d / %d", String info = String.format("%s %d / %d",
@ -58,6 +59,9 @@ public class SetListAdapter extends RecyclerView.Adapter<SetViewHolder> impleme
return false; return false;
} }
}); });
holder.applyBackground(presenter.getAppContext(), set.getId());
} }
@Override @Override

View File

@ -0,0 +1,104 @@
package com.hikapro.backpack.presenter.adapters.helper;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.util.Log;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
import com.hikapro.backpack.App;
import com.hikapro.backpack.R;
/**
* Created by tariel on 26/08/16.
*/
public class AppRater {
private final static String APP_PNAME = "com.hikapro.backpack";
private final static String APP_PREFERENCES = "backpack";
private final static String DO_NOT_SHOW = "notshow";
private final static String COUNT = "count";
private final static String TRIGGER_COUNT = "triggercount";
private final static int COUNT_UNTIL_FIRST_PROMPT = 2;
public static boolean checkRatePrompt() {
boolean ret = false;
SharedPreferences preferences = App.getAppContext().getSharedPreferences(APP_PREFERENCES, Context.MODE_PRIVATE);
if (preferences.getBoolean(DO_NOT_SHOW, false))
ret = false;
else if (preferences.getInt(COUNT, 1) == preferences.getInt(TRIGGER_COUNT, COUNT_UNTIL_FIRST_PROMPT))
ret = true;
return ret;
}
public static void updateSharedPreferences(int countToAdd) {
SharedPreferences preferences = App.getAppContext().getSharedPreferences(APP_PREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
int count = preferences.getInt(COUNT, 0) + countToAdd;
editor.putInt(COUNT, count);
editor.apply();
}
private static void later() {
SharedPreferences preferences = App.getAppContext().getSharedPreferences(APP_PREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
int triggerCount = preferences.getInt(TRIGGER_COUNT, COUNT_UNTIL_FIRST_PROMPT);
triggerCount = triggerCount * 2 + triggerCount;
editor.putInt(TRIGGER_COUNT, triggerCount);
editor.apply();
}
private static void sure() {
SharedPreferences preferences = App.getAppContext().getSharedPreferences(APP_PREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(DO_NOT_SHOW, true);
editor.apply();
}
public static void showRateDialog(final Context context) {
final Dialog dialog = new Dialog(context);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_rate);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
final Button later = (Button) dialog.findViewById(R.id.button_later);
Button rate = (Button) dialog.findViewById(R.id.button_rate);
later.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
try {
later();
dialog.dismiss();
} catch (Exception e) {
Log.e("Rate dialog", "Error while closing", e);
}
}
});
rate.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
sure();
dialog.dismiss();
} catch (Exception e) {
Log.e("Rate dialog", "Error while rating", e);
}
}
});
dialog.show();
}
}

View File

@ -23,7 +23,6 @@ public class HeaderViewCache implements HeaderProvider {
View header = headerViews.get(headerId); View header = headerViews.get(headerId);
if (header == null) { if (header == null) {
//TODO - recycle views
RecyclerView.ViewHolder viewHolder = adapter.onCreateHeaderViewHolder(parent); RecyclerView.ViewHolder viewHolder = adapter.onCreateHeaderViewHolder(parent);
adapter.onBindHeaderViewHolder(viewHolder, position); adapter.onBindHeaderViewHolder(viewHolder, position);
header = viewHolder.itemView; header = viewHolder.itemView;

View File

@ -62,13 +62,6 @@ public class ItemSwipeCallback extends ItemTouchHelper.SimpleCallback {
@Override @Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) { public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
int swipedPosition = viewHolder.getAdapterPosition(); int swipedPosition = viewHolder.getAdapterPosition();
/*
boolean undoOn = adapter.isUndoOn();
if (undoOn) {
adapter.pendingRemoval(swipedPosition);
} else {
adapter.remove(swipedPosition);
}*/
} }
@Override @Override

View File

@ -74,7 +74,6 @@ public class SimpleItemTouchHelperCallback extends ItemTouchHelper.Callback {
itemViewHolder.onItemSelected(); itemViewHolder.onItemSelected();
} }
} }
super.onSelectedChanged(viewHolder, actionState); super.onSelectedChanged(viewHolder, actionState);
} }

View File

@ -45,7 +45,6 @@ public class AddFragment extends Fragment implements com.hikapro.backpack.view.V
// Required empty public constructor // Required empty public constructor
} }
// life cycle -->
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
@ -149,12 +148,5 @@ public class AddFragment extends Fragment implements com.hikapro.backpack.view.V
public Set getSet() { public Set getSet() {
return (Set) getArguments().getSerializable(BUNDLE_SET_KEY); return (Set) getArguments().getSerializable(BUNDLE_SET_KEY);
} }
/*
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_add, menu);
super.onCreateOptionsMenu(menu, inflater);
}
*/
} }

View File

@ -74,7 +74,6 @@ public class ItemDetailFragment extends Fragment implements com.hikapro.backpack
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment
presenter.setView(this); presenter.setView(this);
View view = presenter.onCreateView(inflater, container, savedInstanceState); View view = presenter.onCreateView(inflater, container, savedInstanceState);
Log.i(this.toString(), " onCreateView"); Log.i(this.toString(), " onCreateView");
@ -103,13 +102,13 @@ public class ItemDetailFragment extends Fragment implements com.hikapro.backpack
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
presenter.onDestroy(true); // TODO isChangingConfigurations presenter.onDestroy(true);
Log.i(this.toString(), " onDestroyView"); Log.i(this.toString(), " onDestroyView");
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
presenter.onDestroy(false); // TODO isChangingConfigurations presenter.onDestroy(false);
Log.i(this.toString(), " onDestroy"); Log.i(this.toString(), " onDestroy");
} }
@Override @Override
@ -123,8 +122,6 @@ public class ItemDetailFragment extends Fragment implements com.hikapro.backpack
Log.i(this.toString(), " onSaveInstanceState"); Log.i(this.toString(), " onSaveInstanceState");
} }
// life cycle <--
@Override @Override
public void setPresenter(Presenter.ItemDetail presenter) { public void setPresenter(Presenter.ItemDetail presenter) {
this.presenter = presenter; this.presenter = presenter;

View File

@ -29,6 +29,7 @@ public class ItemListFragment extends Fragment implements com.hikapro.backpack.v
protected static final String BUNDLE_SET_KEY = "BUNDLE_SET_KEY"; protected static final String BUNDLE_SET_KEY = "BUNDLE_SET_KEY";
private com.hikapro.backpack.view.View.ActivityCallback activityCallback; private com.hikapro.backpack.view.View.ActivityCallback activityCallback;
private Presenter.ItemList presenter; private Presenter.ItemList presenter;
private boolean hz;
public ItemListFragment() { public ItemListFragment() {
// Required empty public constructor // Required empty public constructor
@ -50,12 +51,11 @@ public class ItemListFragment extends Fragment implements com.hikapro.backpack.v
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_main, menu); inflater.inflate(R.menu.menu_main, menu);
final MenuItem item = menu.findItem(R.id.action_search);
final SearchView searchView = (SearchView) item.getActionView();
searchView.setOnQueryTextListener(this);
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
final MenuItem item = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) item.getActionView();
searchView.setOnQueryTextListener(this);
Log.i(this.getClass().getName(), " onCreateOptionsMenu");
} }
@Override @Override
@ -65,8 +65,11 @@ public class ItemListFragment extends Fragment implements com.hikapro.backpack.v
@Override @Override
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
if (hz)
presenter.filter(newText); presenter.filter(newText);
return true; if (!hz)
hz = true;
return hz;
} }
@Override @Override
@ -90,13 +93,13 @@ public class ItemListFragment extends Fragment implements com.hikapro.backpack.v
case R.id.action_add : case R.id.action_add :
activityCallback.startAddFragment(getSet()); activityCallback.startAddFragment(getSet());
ret = true; ret = true;
break;
default: default:
ret = super.onOptionsItemSelected(item); ret = super.onOptionsItemSelected(item);
} }
return ret; return ret;
} }
// life cycle -->
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
@ -127,7 +130,6 @@ public class ItemListFragment extends Fragment implements com.hikapro.backpack.v
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment
presenter.setView(this); presenter.setView(this);
View view = presenter.onCreateView(inflater, container, savedInstanceState); View view = presenter.onCreateView(inflater, container, savedInstanceState);
Log.i(this.getClass().getName(), " onCreateView"); Log.i(this.getClass().getName(), " onCreateView");
@ -146,6 +148,7 @@ public class ItemListFragment extends Fragment implements com.hikapro.backpack.v
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
presenter.onResume();
Log.i(this.getClass().getName(), " onResume"); Log.i(this.getClass().getName(), " onResume");
} }
@Override @Override
@ -157,6 +160,7 @@ public class ItemListFragment extends Fragment implements com.hikapro.backpack.v
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
presenter.onDestroy(true); // TODO isChangingConfigurations presenter.onDestroy(true); // TODO isChangingConfigurations
hz = false;
Log.i(this.getClass().getName(), " onDestroyView"); Log.i(this.getClass().getName(), " onDestroyView");
} }
@Override @Override
@ -177,9 +181,6 @@ public class ItemListFragment extends Fragment implements com.hikapro.backpack.v
Log.i(this.getClass().getName(), " onSaveInstanceState"); Log.i(this.getClass().getName(), " onSaveInstanceState");
} }
// life cycle <--
@Override @Override
public void showItemDetail(int setId, Model.Item baseModel, int position) { public void showItemDetail(int setId, Model.Item baseModel, int position) {
activityCallback.startItemDetailFragment(setId, baseModel, position); activityCallback.startItemDetailFragment(setId, baseModel, position);

View File

@ -29,7 +29,6 @@ public class SetListFragment extends Fragment implements com.hikapro.backpack.vi
return ret; return ret;
} }
// life cycle -->
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
@ -60,7 +59,6 @@ public class SetListFragment extends Fragment implements com.hikapro.backpack.vi
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
Log.i(this.toString(), "onCreateView"); Log.i(this.toString(), "onCreateView");
// Inflate the layout for this fragment
presenter.setView(this); presenter.setView(this);
View view = presenter.onCreateView(inflater, container, savedInstanceState); View view = presenter.onCreateView(inflater, container, savedInstanceState);
@ -109,7 +107,6 @@ public class SetListFragment extends Fragment implements com.hikapro.backpack.vi
super.onDetach(); super.onDetach();
Log.i(this.toString(), "onDetach"); Log.i(this.toString(), "onDetach");
} }
// life cycle <--
@Override @Override
public void showItemList(Set set) { public void showItemList(Set set) {

View File

@ -1,10 +1,14 @@
package com.hikapro.backpack.view.recycler; package com.hikapro.backpack.view.recycler;
import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import com.hikapro.backpack.R; import com.hikapro.backpack.R;
@ -19,8 +23,7 @@ public class SetViewHolder extends RecyclerView.ViewHolder implements ItemTouchH
public TextView textView; public TextView textView;
public TextView setInfo; public TextView setInfo;
//GLM_add_resources_SetList private ViewGroup cardContent;
private View view;
private Drawable drawable; private Drawable drawable;
public SetViewHolder(View v) { public SetViewHolder(View v) {
@ -32,20 +35,81 @@ public class SetViewHolder extends RecyclerView.ViewHolder implements ItemTouchH
cardView = (CardView) view.findViewById(R.id.card_view_set); cardView = (CardView) view.findViewById(R.id.card_view_set);
textView = (TextView) view.findViewById(R.id.set_text); textView = (TextView) view.findViewById(R.id.set_text);
setInfo = (TextView) view.findViewById(R.id.set_info); setInfo = (TextView) view.findViewById(R.id.set_info);
cardContent = (ViewGroup) view.findViewById(R.id.card_content);
this.view = view;
drawable = view.getBackground();
} }
//GLM_add_resources_SetList //GLM_add_resources_SetList
@Override @Override
public void onItemClear() { public void onItemClear() {
view.setBackground(drawable); cardContent.setBackgroundColor(cardView.getResources().getColor(R.color.colorListBackground));
if (drawable != null) {
cardContent.setBackground(drawable);
}
drawable = null;
} }
//GLM_add_resources_SetList //GLM_add_resources_SetList
@Override @Override
public void onItemSelected() { public void onItemSelected() {
view.setBackgroundColor(Color.GRAY); this.drawable = cardContent.getBackground();
cardContent.setBackgroundColor(Color.GRAY);
}
public void applyBackground(Context context, int setId) {
Drawable drawable = null;
switch (setId) {
case 1:
drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_1);
break;
case 2:
drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_2);
break;
case 3:
drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_3);
break;
case 4:
drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_4);
break;
case 5:
drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_5);
break;
case 6:
drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_6);
break;
case 7:
// nothing
break;
case 8:
drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_8);
break;
case 9:
// nothing
break;
case 10:
drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_10);
break;
case 11:
// nothing
break;
case 12:
// nothing
break;
case 13:
// nothing
break;
case 14:
drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_14);
break;
default:
drawable = new ColorDrawable(ContextCompat.getColor(context, R.color.colorListBackground));
}
if (drawable != null)
cardContent.setBackground(drawable);
else
cardContent.setBackgroundColor(cardView.getResources().getColor(R.color.colorFullTransparent));
} }
} }

View File

@ -3,10 +3,10 @@
<objectAnimator <objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500" android:duration="@integer/duration"
android:propertyName="y" android:propertyName="y"
android:valueFrom="-1000" android:valueFrom="@integer/valueTransitionYminus"
android:valueTo="0" android:valueTo="@integer/valueTo"
android:valueType="floatType" /> android:valueType="floatType" />
</set> </set>

View File

@ -3,10 +3,10 @@
<objectAnimator <objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500" android:duration="@integer/duration"
android:propertyName="x" android:propertyName="x"
android:valueFrom="1000" android:valueFrom="@integer/valueTransitionXplus"
android:valueTo="0" android:valueTo="@integer/valueTo"
android:valueType="floatType" /> android:valueType="floatType" />
</set> </set>

View File

@ -3,10 +3,10 @@
<objectAnimator <objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500" android:duration="@integer/duration"
android:propertyName="x" android:propertyName="x"
android:valueFrom="-1000" android:valueFrom="@integer/valueTransitionXminus"
android:valueTo="0" android:valueTo="@integer/valueTo"
android:valueType="floatType" /> android:valueType="floatType" />
</set> </set>

View File

@ -3,10 +3,10 @@
<objectAnimator <objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500" android:duration="@integer/duration"
android:propertyName="y" android:propertyName="y"
android:valueFrom="1000" android:valueFrom="@integer/valueTransitionYplus"
android:valueTo="0" android:valueTo="@integer/valueTo"
android:valueType="floatType" /> android:valueType="floatType" />
</set> </set>

View File

@ -3,10 +3,10 @@
<objectAnimator <objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500" android:duration="@integer/duration"
android:propertyName="y" android:propertyName="y"
android:valueFrom="0" android:valueFrom="@integer/valueTo"
android:valueTo="-1000" android:valueTo="@integer/valueTransitionYminus"
android:valueType="floatType" /> android:valueType="floatType" />
</set> </set>

View File

@ -3,10 +3,10 @@
<objectAnimator <objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500" android:duration="@integer/duration"
android:propertyName="x" android:propertyName="x"
android:valueFrom="0" android:valueFrom="@integer/valueTo"
android:valueTo="1000" android:valueTo="@integer/valueTransitionXplus"
android:valueType="floatType" /> android:valueType="floatType" />
</set> </set>

View File

@ -3,10 +3,10 @@
<objectAnimator <objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500" android:duration="@integer/duration"
android:propertyName="x" android:propertyName="x"
android:valueFrom="0" android:valueFrom="@integer/valueTo"
android:valueTo="-1000" android:valueTo="@integer/valueTransitionXminus"
android:valueType="floatType" /> android:valueType="floatType" />
</set> </set>

View File

@ -3,10 +3,10 @@
<objectAnimator <objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500" android:duration="@integer/duration"
android:propertyName="y" android:propertyName="y"
android:valueFrom="0" android:valueFrom="@integer/valueTo"
android:valueTo="1000" android:valueTo="@integer/valueTransitionYplus"
android:valueType="floatType" /> android:valueType="floatType" />
</set> </set>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 260 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 579 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 412 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 973 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 579 B

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 847 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorShareBtnBackground" />
<corners android:radius="5dp" />
<stroke android:width="2px" android:color="#FFFFFF" />
</shape>

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:padding="10dp">
<solid android:color="#e0f2ff"/>
<corners android:topLeftRadius="10dip"/>
</shape>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:padding="10dp">
<solid android:color="#e0f2ff"/>
<corners android:topRightRadius="10dip"/>
</shape>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#e0f2ff"/>
<stroke android:width="1dip" android:color="#FFe0f2ff" />
<corners android:radius="10dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View File

@ -2,33 +2,37 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:enabled="false" android:enabled="false" >
android:paddingLeft="@dimen/margin_standard"
android:paddingRight="@dimen/margin_standard">
<Button <Button
android:id="@+id/action_add_cancel" android:id="@+id/action_add_cancel"
style="@style/ActionBarButtonWhite" style="@style/ActionBarButtonWhiteStart"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/cancel_button" android:text="@string/cancel_button"
android:layout_alignParentStart="true"/> android:layout_alignParentStart="true"
android:layout_centerVertical="true"
/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="ADD AN ITEM"
android:textSize="@dimen/text_size_medium"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:gravity="center" android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/add_an_item"
android:textAllCaps="true"
android:textSize="@dimen/text_action_bar_header"
android:textColor="@color/white" android:textColor="@color/white"
android:textStyle="bold"/> android:textStyle="bold"/>
<Button <Button
android:id="@+id/action_add_save" android:id="@+id/action_add_save"
style="@style/ActionBarButtonWhite" style="@style/ActionBarButtonWhiteEnd"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/save_button" android:text="@string/save_button"
android:layout_alignParentEnd="true"/> android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
/>
</RelativeLayout> </RelativeLayout>

View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="@dimen/dlg_restore_width"
android:layout_height="@dimen/dlg_restore_height">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:background="@android:color/black" >
<TextView
android:id="@+id/txt_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:text="@string/dlg_restore_header"
android:textSize="@dimen/dlg_restore_header"
android:textColor="@color/colorText"
android:textAppearance="?android:attr/textAppearanceLarge" />
<com.hikapro.backpack.presenter.adapters.helper.AutoResizeTextView
android:id="@+id/txt_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:text="@string/dlg_restore_txt"
android:textSize="@dimen/dlg_restore_txt"
android:textColor="@color/colorRestoreDialogTxt"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dlg_restore_btn_height"
android:orientation="horizontal">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/colorRestoreBtnBackground">
<Button
android:id="@+id/button_ok"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/dlg_restore_btn"
android:textColor="@color/colorText"
android:textSize="@dimen/dlg_restore_txt"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="?android:attr/selectableItemBackground" />
</LinearLayout>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/colorCancelBtnBackground" >
<Button
android:id="@+id/button_cancel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/dlg_cancel_btn"
android:textColor="@color/colorText"
android:textSize="@dimen/dlg_restore_txt"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="?android:attr/selectableItemBackground" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="@dimen/dlg_restore_width"
android:layout_height="@dimen/dlg_restore_height">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:background="@android:color/black" >
<TextView
android:id="@+id/txt_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:text="@string/dlg_rate_header"
android:textSize="@dimen/dlg_restore_header"
android:textColor="@color/colorText"
android:textAppearance="?android:attr/textAppearanceLarge" />
<com.hikapro.backpack.presenter.adapters.helper.AutoResizeTextView
android:id="@+id/txt_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:text="@string/dlg_rate_txt"
android:textSize="@dimen/dlg_restore_txt"
android:textColor="@color/colorRestoreDialogTxt"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dlg_restore_btn_height"
android:orientation="horizontal">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/colorRestoreBtnBackground">
<Button
android:id="@+id/button_rate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/dlg_rate_btn"
android:textColor="@color/colorText"
android:textSize="@dimen/dlg_restore_txt"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="?android:attr/selectableItemBackground" />
</LinearLayout>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/colorCancelBtnBackground" >
<Button
android:id="@+id/button_later"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/dlg_later_btn"
android:textColor="@color/colorText"
android:textSize="@dimen/dlg_restore_txt"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="?android:attr/selectableItemBackground" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="320dp"
android:layout_height="230dp"
android:background="@drawable/twitter_dlg">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="66dp"
android:orientation="horizontal" >
<Button
android:id="@+id/button_cancel"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="Cancel"
android:gravity="start|center_vertical"
android:textColor="#3333cc"
android:textSize="18sp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:paddingStart="16dp"
android:background="@drawable/tweeter_button"
style="@style/Widget.AppCompat.Button.Borderless.Colored"/>
<TextView
android:id="@+id/txt_header"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="16dp"
android:text="Twitter"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button_post"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="Post"
android:gravity="end|center_vertical"
android:paddingEnd="16dp"
android:textColor="#3333cc"
android:textSize="18sp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="@drawable/tweeter_button2"
style="@style/Widget.AppCompat.Button.Borderless.Colored"/>
</LinearLayout>
<View
android:layout_marginTop="0dp"
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#666699">
</View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingTop="4dp"
android:orientation="horizontal">
<EditText
android:id="@+id/message"
android:layout_width="220dp"
android:gravity="top"
android:paddingStart="16dp"
android:text="PACK WITH ME - ready-to-go travel checklists"
android:layout_height="match_parent"
android:maxLength="140"
android:background="@null"/>
<ImageView
android:id="@+id/image_to_post"
android:layout_width="84dp"
android:layout_height="84dp"
android:contentDescription="Sharing image."/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="16dp"
android:orientation="horizontal">
<TextView
android:id="@+id/chars_left"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="74"
android:paddingStart="16dp"/>
</LinearLayout>
</LinearLayout>

View File

@ -1,17 +1,13 @@
<ScrollView <LinearLayout
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="com.hikapro.backpack.view.fragments.AddFragment" tools:context="com.hikapro.backpack.view.fragments.AddFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorListBackground">
<LinearLayout
android:id="@+id/fragment_add_main_layout" android:id="@+id/fragment_add_main_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical"
android:background="@color/colorListBackground">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -21,7 +17,7 @@
android:id="@+id/add_search" android:id="@+id/add_search"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:textColor="@color/colorText"/> android:theme="@style/ThemeOverlay.AppCompat.Dark"/>
</LinearLayout> </LinearLayout>
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
@ -30,6 +26,10 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView> </android.support.v7.widget.RecyclerView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout <RelativeLayout
android:id="@+id/add_item_category_container" android:id="@+id/add_item_category_container"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -54,5 +54,8 @@
</com.hikapro.backpack.presenter.adapters.helper.FlowLayout> </com.hikapro.backpack.presenter.adapters.helper.FlowLayout>
</RelativeLayout> </RelativeLayout>
</LinearLayout>
</ScrollView> </ScrollView>
</LinearLayout>

View File

@ -4,7 +4,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:animateLayoutChanges="true" android:animateLayoutChanges="true"
android:background="@color/colorUiMainbackground2"> android:background="@color/colorListBackground">
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -9,7 +9,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:background="@color/colorListBackground"> android:id="@+id/item_list_container">
<com.hikapro.backpack.presenter.adapters.helper.items.swipe2.SwipableRecycler <com.hikapro.backpack.presenter.adapters.helper.items.swipe2.SwipableRecycler
android:id="@+id/items_recycler" android:id="@+id/items_recycler"

Some files were not shown because too many files have changed in this diff Show More