diff --git a/app/build.gradle b/app/build.gradle index adb878d..ba385e9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,14 +1,14 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 + compileSdkVersion 27 buildToolsVersion "26.0.2" defaultConfig { applicationId 'com.samebits.beacon.locator' minSdkVersion 18 targetSdkVersion 22 - versionCode 116 - versionName '1.1.6' + versionCode 117 + versionName '1.1.7' testApplicationId 'com.samebits.beacon.locator.test' } buildTypes { @@ -49,7 +49,7 @@ android { } dependencies { - final SUPPORT_LIBRARY_VERSION = '25.3.1' + final SUPPORT_LIBRARY_VERSION = '27.0.0' final DAGGER_VERSION = '2.11' final ALTBEACON_VERSION = '2.12.3' @@ -66,5 +66,6 @@ dependencies { compile "com.google.dagger:dagger:$DAGGER_VERSION" annotationProcessor "com.google.dagger:dagger-compiler:$DAGGER_VERSION" provided 'org.glassfish:javax.annotation:10.0-b28' - compile 'com.jakewharton:butterknife:7.0.1' + compile 'com.jakewharton:butterknife:8.8.0' + annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.0' } diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index e3c0910..6621c1a 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -15,3 +15,7 @@ #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} + +-keep class **$$ViewBinder { *; } +-keep class **$ViewHolder { *; } +-keep class butterknife.**$Finder { *; } \ No newline at end of file diff --git a/app/src/main/java/com/samebits/beacon/locator/data/DataManager.java b/app/src/main/java/com/samebits/beacon/locator/data/DataManager.java index c2c8cc2..85ea26b 100644 --- a/app/src/main/java/com/samebits/beacon/locator/data/DataManager.java +++ b/app/src/main/java/com/samebits/beacon/locator/data/DataManager.java @@ -113,4 +113,8 @@ public TrackedBeacon getBeacon(String id) { public boolean updateBeaconDistance(final String id, double distance) { return mStoreService.updateBeaconDistance(id, distance); } + + public boolean isBeaconExists(String id) { + return mStoreService.isBeaconExists(id); + } } \ No newline at end of file diff --git a/app/src/main/java/com/samebits/beacon/locator/data/DbStoreService.java b/app/src/main/java/com/samebits/beacon/locator/data/DbStoreService.java index 3bda585..bb396d3 100644 --- a/app/src/main/java/com/samebits/beacon/locator/data/DbStoreService.java +++ b/app/src/main/java/com/samebits/beacon/locator/data/DbStoreService.java @@ -197,6 +197,26 @@ public boolean updateBeacon(TrackedBeacon beacon) { return (numUpdated == 0) ? false : true; } + @Override + public boolean isBeaconExists(String id) { + + SQLiteDatabase db = getReadableDatabase(); + Cursor cursor = db.rawQuery("SELECT EXISTS (SELECT * FROM " + ScanColumns.TABLE_NAME + + " WHERE " +ScanColumns.COLUMN_ID +"=? LIMIT 1)" , new String[]{id}); + + if (cursor != null) { + if (cursor.moveToFirst()) { + if (cursor.getInt(0) == 1) { + cursor.close(); + return true; + } else { + cursor.close(); + } + } + } + return false; + } + @Override public TrackedBeacon getBeacon(String id) { TrackedBeacon beacon = new TrackedBeacon(); @@ -471,6 +491,7 @@ public List getEnabledBeaconActionsByEvent(int eventType, String b return actions; } + @Override public boolean deleteBeacon(String id, boolean cascade) { SQLiteDatabase db = getWritableDatabase(); diff --git a/app/src/main/java/com/samebits/beacon/locator/data/StoreService.java b/app/src/main/java/com/samebits/beacon/locator/data/StoreService.java index 6cb47f2..e7ab3db 100644 --- a/app/src/main/java/com/samebits/beacon/locator/data/StoreService.java +++ b/app/src/main/java/com/samebits/beacon/locator/data/StoreService.java @@ -55,4 +55,6 @@ public interface StoreService { boolean updateBeaconActionEnable(final int id, boolean enable); List getEnabledBeaconActionsByEvent(final int eventType, final String beaconId); + + boolean isBeaconExists(String id); } diff --git a/app/src/main/java/com/samebits/beacon/locator/ui/activity/BeaconActionActivity.java b/app/src/main/java/com/samebits/beacon/locator/ui/activity/BeaconActionActivity.java index e635b34..9334b1e 100644 --- a/app/src/main/java/com/samebits/beacon/locator/ui/activity/BeaconActionActivity.java +++ b/app/src/main/java/com/samebits/beacon/locator/ui/activity/BeaconActionActivity.java @@ -32,17 +32,17 @@ import com.samebits.beacon.locator.ui.adapter.DetailFragmentPagerAdapter; import com.samebits.beacon.locator.util.Constants; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; public class BeaconActionActivity extends BaseActivity implements ViewPager.OnPageChangeListener { - @Bind(R.id.toolbar) + @BindView(R.id.toolbar) Toolbar toolbar; - @Bind(R.id.viewpager) + @BindView(R.id.viewpager) ViewPager viewPager; - @Bind(R.id.sliding_tabs) + @BindView(R.id.sliding_tabs) TabLayout slidingTabs; private ActionBeacon mActionBeacon; diff --git a/app/src/main/java/com/samebits/beacon/locator/ui/activity/MainNavigationActivity.java b/app/src/main/java/com/samebits/beacon/locator/ui/activity/MainNavigationActivity.java index a906033..e96f63a 100644 --- a/app/src/main/java/com/samebits/beacon/locator/ui/activity/MainNavigationActivity.java +++ b/app/src/main/java/com/samebits/beacon/locator/ui/activity/MainNavigationActivity.java @@ -32,7 +32,7 @@ import android.support.design.widget.FloatingActionButton; import android.support.design.widget.NavigationView; import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; @@ -46,6 +46,7 @@ import com.samebits.beacon.locator.BeaconLocatorApp; import com.samebits.beacon.locator.R; import com.samebits.beacon.locator.model.TrackedBeacon; +import com.samebits.beacon.locator.ui.fragment.BeaconFragment; import com.samebits.beacon.locator.ui.fragment.DetectedBeaconsFragment; import com.samebits.beacon.locator.ui.fragment.ScanFragment; import com.samebits.beacon.locator.ui.fragment.ScanRadarFragment; @@ -55,29 +56,33 @@ import org.altbeacon.beacon.BeaconManager; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; +import butterknife.Unbinder; public class MainNavigationActivity extends BaseActivity - implements NavigationView.OnNavigationItemSelectedListener { + implements NavigationView.OnNavigationItemSelectedListener, BeaconFragment.OnTrackedBeaconSelectedListener { public static final int PERMISSION_REQUEST_COARSE_LOCATION = 1; - @Bind(R.id.fab) + @BindView(R.id.fab) FloatingActionButton fab; - @Bind(R.id.drawer_layout) + @BindView(R.id.drawer_layout) DrawerLayout drawer; - @Bind(R.id.toolbar) + @BindView(R.id.toolbar) Toolbar toolbar; - @Bind(R.id.nav_view) + @BindView(R.id.nav_view) NavigationView navigationView; BeaconManager mBeaconManager; - TrackedBeacon mBeacon; + + + TrackedBeacon mSelectedBeacon; + private Unbinder unbinder; public static Intent getStartIntent(Context context) { return new Intent(context, MainNavigationActivity.class); @@ -102,7 +107,7 @@ void navAction() { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_navigation); - ButterKnife.bind(this); + unbinder = ButterKnife.bind(this); setupToolbar(); @@ -116,7 +121,7 @@ protected void onCreate(Bundle savedInstanceState) { readExtras(); if (null == savedInstanceState) { - if (mBeacon != null) { + if (mSelectedBeacon != null) { launchTrackedListView(); } else { launchScanBeaconView(); @@ -125,10 +130,16 @@ protected void onCreate(Bundle savedInstanceState) { } + @Override + protected void onDestroy() { + unbinder.unbind(); + super.onDestroy(); + } + protected void readExtras() { Intent intent = getIntent(); if (intent.getExtras() != null) { - mBeacon = intent.getExtras().getParcelable(Constants.ARG_BEACON); + mSelectedBeacon = intent.getExtras().getParcelable(Constants.ARG_BEACON); } } @@ -145,7 +156,7 @@ private void setupToolbar() { this, drawer, toolbar, R.string.nav_drawer_open, R.string.nav_drawer_close); - drawer.setDrawerListener(toggle); + drawer.addDrawerListener(toggle); toggle.syncState(); } @@ -274,47 +285,55 @@ public boolean onNavigationItemSelected(MenuItem item) { } - private void addScanBeaconFragment() { - FragmentManager fragmentManager = getSupportFragmentManager(); - if (fragmentManager != null) { - if (checkFragmentInstance(R.id.content_frame, DetectedBeaconsFragment.class) == null) { - fragmentManager - .beginTransaction() - .replace(R.id.content_frame, DetectedBeaconsFragment.newInstance(), Constants.TAG_FRAGMENT_SCAN_LIST) - .commit(); + private void createOrResumeFragment(String fragmentTag) { + android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction ft = fragmentManager.beginTransaction(); + boolean fragmentPopped = false; + + Fragment fragment = fragmentManager.findFragmentByTag(fragmentTag); + + if (fragmentManager.getBackStackEntryCount() > 0){ + fragmentPopped = fragmentManager.popBackStackImmediate(fragmentTag, 0); + } + + if(!fragmentPopped && fragment == null){ + //Create an new instance if it is null and add it to stack + switch(fragmentTag) { + case Constants.TAG_FRAGMENT_SCAN_LIST: + fragment = DetectedBeaconsFragment.newInstance(); + break; + case Constants.TAG_FRAGMENT_SCAN_RADAR: + fragment = ScanRadarFragment.newInstance(); + break; + case Constants.TAG_FRAGMENT_TRACKED_BEACON_LIST: + fragment = TrackedBeaconsFragment.newInstance(); + if (mSelectedBeacon != null) { + Bundle bundles = new Bundle(); + bundles.putParcelable(Constants.ARG_BEACON, mSelectedBeacon); + fragment.setArguments(bundles); + } + break; } + ft.addToBackStack(fragmentTag); } + ft.replace(R.id.content_frame, fragment, fragmentTag); + + ft.commit(); + + fragmentManager.executePendingTransactions(); + + } + + private void addScanBeaconFragment() { + createOrResumeFragment(Constants.TAG_FRAGMENT_SCAN_LIST); } private void addRadarScanFragment() { - FragmentManager fragmentManager = getSupportFragmentManager(); - if (fragmentManager != null) { - if (checkFragmentInstance(R.id.content_frame, ScanRadarFragment.class) == null) { - fragmentManager - .beginTransaction() - .replace(R.id.content_frame, ScanRadarFragment.newInstance(), Constants.TAG_FRAGMENT_SCAN_RADAR) - .commit(); - } - } + createOrResumeFragment(Constants.TAG_FRAGMENT_SCAN_RADAR); } private void addTrackedListFragment() { - FragmentManager fragmentManager = getSupportFragmentManager(); - if (fragmentManager != null) { - Fragment frg = checkFragmentInstance(R.id.content_frame, TrackedBeaconsFragment.class); - if (frg == null) { - TrackedBeaconsFragment tFrg = TrackedBeaconsFragment.newInstance(); - if (mBeacon != null) { - Bundle bundles = new Bundle(); - bundles.putParcelable(Constants.ARG_BEACON, mBeacon); - tFrg.setArguments(bundles); - } - fragmentManager - .beginTransaction() - .replace(R.id.content_frame, tFrg, Constants.TAG_FRAGMENT_TRACKED_BEACON_LIST) - .commit(); - } - } + createOrResumeFragment(Constants.TAG_FRAGMENT_TRACKED_BEACON_LIST); } public void hideFab() { @@ -365,6 +384,7 @@ public void onHidden(FloatingActionButton fab) { }); } + private void launchScanBeaconView() { addScanBeaconFragment(); } @@ -377,4 +397,9 @@ private void launchTrackedListView() { addTrackedListFragment(); } + @Override + public void onBeaconSelected(TrackedBeacon beacon) { + mSelectedBeacon = beacon; + launchTrackedListView(); + } } diff --git a/app/src/main/java/com/samebits/beacon/locator/ui/adapter/BeaconAdapter.java b/app/src/main/java/com/samebits/beacon/locator/ui/adapter/BeaconAdapter.java index 3303c59..5386664 100644 --- a/app/src/main/java/com/samebits/beacon/locator/ui/adapter/BeaconAdapter.java +++ b/app/src/main/java/com/samebits/beacon/locator/ui/adapter/BeaconAdapter.java @@ -21,7 +21,7 @@ import android.support.v7.widget.RecyclerView; import com.samebits.beacon.locator.model.IManagedBeacon; -import com.samebits.beacon.locator.ui.fragment.BaseFragment; +import com.samebits.beacon.locator.ui.fragment.BeaconFragment; import com.samebits.beacon.locator.util.BeaconUtil; import java.util.LinkedHashMap; @@ -35,7 +35,7 @@ public abstract class BeaconAdapter extends RecyclerView.Adapter { protected Map mBeacons = new LinkedHashMap(); - protected BaseFragment mFragment; + protected BeaconFragment mFragment; protected OnBeaconLongClickListener onBeaconLongClickListener; diff --git a/app/src/main/java/com/samebits/beacon/locator/ui/adapter/DetectedBeaconAdapter.java b/app/src/main/java/com/samebits/beacon/locator/ui/adapter/DetectedBeaconAdapter.java index 0b86f20..bfc51e4 100644 --- a/app/src/main/java/com/samebits/beacon/locator/ui/adapter/DetectedBeaconAdapter.java +++ b/app/src/main/java/com/samebits/beacon/locator/ui/adapter/DetectedBeaconAdapter.java @@ -27,7 +27,7 @@ import com.samebits.beacon.locator.R; import com.samebits.beacon.locator.databinding.ItemDetectedBeaconBinding; import com.samebits.beacon.locator.model.DetectedBeacon; -import com.samebits.beacon.locator.ui.fragment.BaseFragment; +import com.samebits.beacon.locator.ui.fragment.BeaconFragment; import com.samebits.beacon.locator.viewModel.DetectedBeaconViewModel; import org.altbeacon.beacon.Beacon; @@ -40,7 +40,7 @@ */ public class DetectedBeaconAdapter extends BeaconAdapter { - public DetectedBeaconAdapter(BaseFragment fragment) { + public DetectedBeaconAdapter(BeaconFragment fragment) { mFragment = fragment; } diff --git a/app/src/main/java/com/samebits/beacon/locator/ui/adapter/TrackedBeaconAdapter.java b/app/src/main/java/com/samebits/beacon/locator/ui/adapter/TrackedBeaconAdapter.java index bd9366e..5fa5a9d 100644 --- a/app/src/main/java/com/samebits/beacon/locator/ui/adapter/TrackedBeaconAdapter.java +++ b/app/src/main/java/com/samebits/beacon/locator/ui/adapter/TrackedBeaconAdapter.java @@ -32,7 +32,7 @@ import com.samebits.beacon.locator.model.ActionBeacon; import com.samebits.beacon.locator.model.IManagedBeacon; import com.samebits.beacon.locator.model.TrackedBeacon; -import com.samebits.beacon.locator.ui.fragment.BaseFragment; +import com.samebits.beacon.locator.ui.fragment.BeaconFragment; import com.samebits.beacon.locator.ui.fragment.TrackedBeaconsFragment; import com.samebits.beacon.locator.ui.view.WrapLinearLayoutManager; import com.samebits.beacon.locator.util.Constants; @@ -48,7 +48,7 @@ public class TrackedBeaconAdapter extends BeaconAdapter mActionAdapters = new HashMap<>(); - public TrackedBeaconAdapter(BaseFragment fragment) { + public TrackedBeaconAdapter(BeaconFragment fragment) { mFragment = fragment; } diff --git a/app/src/main/java/com/samebits/beacon/locator/ui/fragment/BaseFragment.java b/app/src/main/java/com/samebits/beacon/locator/ui/fragment/BeaconFragment.java similarity index 68% rename from app/src/main/java/com/samebits/beacon/locator/ui/fragment/BaseFragment.java rename to app/src/main/java/com/samebits/beacon/locator/ui/fragment/BeaconFragment.java index a30e86a..dc685ff 100644 --- a/app/src/main/java/com/samebits/beacon/locator/ui/fragment/BaseFragment.java +++ b/app/src/main/java/com/samebits/beacon/locator/ui/fragment/BeaconFragment.java @@ -18,6 +18,7 @@ package com.samebits.beacon.locator.ui.fragment; +import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.View; @@ -25,22 +26,29 @@ import com.samebits.beacon.locator.BuildConfig; import com.samebits.beacon.locator.R; +import com.samebits.beacon.locator.model.TrackedBeacon; import com.samebits.beacon.locator.ui.activity.MainNavigationActivity; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.Unbinder; /** * Created by vitas on 8/12/15. */ -public class BaseFragment extends Fragment { +public class BeaconFragment extends Fragment { protected boolean mNeedFab; - + protected Unbinder unbinder; protected boolean isDebug() { return BuildConfig.DEBUG; } + private OnTrackedBeaconSelectedListener mBeaconSelectedListener; + + public interface OnTrackedBeaconSelectedListener { + void onBeaconSelected(TrackedBeacon beacon); + } @Override public void onActivityCreated(Bundle savedInstanceState) { @@ -50,6 +58,18 @@ public void onActivityCreated(Bundle savedInstanceState) { } } + @Override + public void onAttach(Context context) { + super.onAttach(context); + + try { + mBeaconSelectedListener = (OnTrackedBeaconSelectedListener) context; + } catch (ClassCastException e) { + throw new ClassCastException(context.toString() + + " must implement OnTrackedBeaconSelectedListener"); + } + } + @Override public void onStart() { super.onStart(); @@ -76,11 +96,18 @@ public void setNeedFab(boolean mNeedFab) { public class EmptyView { - @Bind(R.id.empty_text) + @BindView(R.id.empty_text) TextView text; public EmptyView(View view) { ButterKnife.bind(this, view); } } + + public void selectBeacon(TrackedBeacon trackedBeacon) { + if (mBeaconSelectedListener != null) { + mBeaconSelectedListener.onBeaconSelected(trackedBeacon); + } + } + } \ No newline at end of file diff --git a/app/src/main/java/com/samebits/beacon/locator/ui/fragment/DetectedBeaconsFragment.java b/app/src/main/java/com/samebits/beacon/locator/ui/fragment/DetectedBeaconsFragment.java index 23e6b59..5afb927 100644 --- a/app/src/main/java/com/samebits/beacon/locator/ui/fragment/DetectedBeaconsFragment.java +++ b/app/src/main/java/com/samebits/beacon/locator/ui/fragment/DetectedBeaconsFragment.java @@ -18,7 +18,6 @@ package com.samebits.beacon.locator.ui.fragment; -import android.content.Intent; import android.os.Bundle; import android.os.CountDownTimer; import android.support.v7.app.ActionBar; @@ -38,7 +37,6 @@ import com.samebits.beacon.locator.R; import com.samebits.beacon.locator.model.IManagedBeacon; import com.samebits.beacon.locator.model.TrackedBeacon; -import com.samebits.beacon.locator.ui.activity.MainNavigationActivity; import com.samebits.beacon.locator.ui.adapter.BeaconAdapter; import com.samebits.beacon.locator.ui.adapter.DetectedBeaconAdapter; import com.samebits.beacon.locator.ui.view.ContextMenuRecyclerView; @@ -50,7 +48,7 @@ import java.util.Collection; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; @@ -62,14 +60,14 @@ public class DetectedBeaconsFragment extends ScanFragment implements BeaconAdapt //40 sec timeout for scanning static final int SCAN_TIMEOUT = 40000; protected CountDownTimer mTimer; - @Bind(R.id.recycler_detected_beacons) + @BindView(R.id.recycler_detected_beacons) ContextMenuRecyclerView mListBeacons; - @Bind(R.id.progress_indicator) + @BindView(R.id.progress_indicator) ProgressBar mProgressBar; - @Bind(R.id.empty_scan_view) + @BindView(R.id.empty_scan_view) ViewStub mEmpty; EmptyView mEmptyView; - @Bind(R.id.toolbar) + @BindView(R.id.toolbar) Toolbar mToolbar; private DetectedBeaconAdapter mBeaconsAdapter; @@ -83,12 +81,13 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mBeaconsAdapter = new DetectedBeaconAdapter(this); mBeaconsAdapter.setOnBeaconLongClickListener(this); + setRetainInstance(true); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View fragmentView = inflater.inflate(R.layout.fragment_scan_beacons, container, false); - ButterKnife.bind(this, fragmentView); + unbinder = ButterKnife.bind(this, fragmentView); setupToolbar(); setupRecyclerView(); @@ -101,7 +100,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa public void onDestroyView() { super.onDestroyView(); mTimer.cancel(); - ButterKnife.unbind(this); + unbinder.unbind(); } private void setupToolbar() { @@ -146,7 +145,7 @@ private void stopScanTimeout() { } private void emptyListSetup() { - if (mBeaconsAdapter.getItemCount() == 0) { + if (mBeaconsAdapter != null && mBeaconsAdapter.getItemCount() == 0) { if (mEmpty != null) { mEmpty.setVisibility(View.VISIBLE); } @@ -233,10 +232,7 @@ public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_manage_add: - //find better way to change fragment from scan to tracked - Intent intent = MainNavigationActivity.getStartIntent(getActivity()); - intent.putExtra(Constants.ARG_BEACON, new TrackedBeacon((IManagedBeacon) mBeaconsAdapter.getItem(info.position))); - startActivity(intent); + selectBeacon(new TrackedBeacon((IManagedBeacon) mBeaconsAdapter.getItem(info.position))); return true; case R.id.action_filter_add: //TODO diff --git a/app/src/main/java/com/samebits/beacon/locator/ui/fragment/ScanFragment.java b/app/src/main/java/com/samebits/beacon/locator/ui/fragment/ScanFragment.java index 65d7b18..ce7608f 100644 --- a/app/src/main/java/com/samebits/beacon/locator/ui/fragment/ScanFragment.java +++ b/app/src/main/java/com/samebits/beacon/locator/ui/fragment/ScanFragment.java @@ -42,7 +42,7 @@ /** * Created by vitas on 8/11/15. */ -public abstract class ScanFragment extends BaseFragment implements BeaconConsumer, RangeNotifier { +public abstract class ScanFragment extends BeaconFragment implements BeaconConsumer, RangeNotifier { final static String STATE_SCANNING = "STATE_SCANNING"; @@ -55,15 +55,17 @@ public abstract class ScanFragment extends BaseFragment implements BeaconConsume @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mBeaconManager = BeaconLocatorApp.from(getActivity()).getComponent().beaconManager(); mRegion = new Region(PreferencesUtil.getDefaultRegionName(getApplicationContext()), null, null, null); mBeaconManager.bind(this); - mBeaconManager.setRangeNotifier(this); + mBeaconManager.addRangeNotifier(this); setNeedFab(true); if (savedInstanceState != null) { needContinueScan = savedInstanceState.getBoolean(STATE_SCANNING); } + } @Override diff --git a/app/src/main/java/com/samebits/beacon/locator/ui/fragment/ScanRadarFragment.java b/app/src/main/java/com/samebits/beacon/locator/ui/fragment/ScanRadarFragment.java index 91f68f5..02cb3c5 100644 --- a/app/src/main/java/com/samebits/beacon/locator/ui/fragment/ScanRadarFragment.java +++ b/app/src/main/java/com/samebits/beacon/locator/ui/fragment/ScanRadarFragment.java @@ -36,19 +36,19 @@ import java.util.Collection; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; public class ScanRadarFragment extends ScanFragment { - @Bind(R.id.toolbar) + @BindView(R.id.toolbar) Toolbar mToolbar; - @Bind(R.id.radar) + @BindView(R.id.radar) RadarScanView mRadar; - @Bind(R.id.distance) + @BindView(R.id.distance) TextView mDistView; SensorManager mSensorManager; @@ -71,7 +71,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View fragmentView = inflater.inflate(R.layout.fragment_scan_radar, container, false); - ButterKnife.bind(this, fragmentView); + unbinder = ButterKnife.bind(this, fragmentView); setupToolbar(); @@ -125,7 +125,7 @@ private void setupToolbar() { @Override public void onDestroyView() { - ButterKnife.unbind(this); + unbinder.unbind(); super.onDestroyView(); } diff --git a/app/src/main/java/com/samebits/beacon/locator/ui/fragment/TrackedBeaconsFragment.java b/app/src/main/java/com/samebits/beacon/locator/ui/fragment/TrackedBeaconsFragment.java index 185df6e..7a9c5cd 100644 --- a/app/src/main/java/com/samebits/beacon/locator/ui/fragment/TrackedBeaconsFragment.java +++ b/app/src/main/java/com/samebits/beacon/locator/ui/fragment/TrackedBeaconsFragment.java @@ -48,23 +48,23 @@ import com.samebits.beacon.locator.ui.view.ContextMenuRecyclerView; import com.samebits.beacon.locator.util.Constants; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; /** * Created by vitas on 9/11/15. */ -public class TrackedBeaconsFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener, BeaconAdapter.OnBeaconLongClickListener { +public class TrackedBeaconsFragment extends BeaconFragment implements SwipeRefreshLayout.OnRefreshListener, BeaconAdapter.OnBeaconLongClickListener { - @Bind(R.id.recycler_beacons) + @BindView(R.id.recycler_beacons) ContextMenuRecyclerView mListBeacons; - @Bind(R.id.progress_indicator) + @BindView(R.id.progress_indicator) ProgressBar mProgressBar; - @Bind(R.id.empty_view) + @BindView(R.id.empty_view) ViewStub mEmpty; EmptyView mEmptyView; - @Bind(R.id.toolbar) + @BindView(R.id.toolbar) Toolbar mToolbar; private TrackedBeaconAdapter mBeaconsAdapter; private DataManager mDataManager; @@ -74,25 +74,23 @@ public static TrackedBeaconsFragment newInstance() { return beaconsFragment; } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setRetainInstance(true); mDataManager = BeaconLocatorApp.from(getActivity()).getComponent().dataManager(); mBeaconsAdapter = new TrackedBeaconAdapter(this); mBeaconsAdapter.setOnBeaconLongClickListener(this); - setRetainInstance(true); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View fragmentView = inflater.inflate(R.layout.fragment_tracked_beacons, container, false); - ButterKnife.bind(this, fragmentView); + unbinder = ButterKnife.bind(this, fragmentView); setupToolbar(); setupRecyclerView(); - //setupSwipe(); loadBeacons(); return fragmentView; @@ -102,9 +100,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa @Override public void onDestroyView() { super.onDestroyView(); - ButterKnife.unbind(this); + unbinder.unbind(); } + + private void setupToolbar() { ((AppCompatActivity) getActivity()).setSupportActionBar(mToolbar); ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); @@ -148,10 +148,10 @@ private void emptyListUpdate() { private void loadBeacons() { showLoadingViews(); - mBeaconsAdapter.insertBeacons(mDataManager.getAllBeacons()); - getExtras(); + mBeaconsAdapter.insertBeacons(mDataManager.getAllBeacons()); + emptyListUpdate(); hideLoadingViews(); } @@ -162,17 +162,15 @@ private void getExtras() { TrackedBeacon beacon = getArguments().getParcelable(Constants.ARG_BEACON); if (beacon != null) { if (!mBeaconsAdapter.isItemExists(beacon.getId())) { - if (mDataManager.createBeacon(beacon)) { - mBeaconsAdapter.insertBeacon(beacon); - } else { - //TODO + if (!mDataManager.isBeaconExists(beacon.getId())) { + if (!mDataManager.createBeacon(beacon)) { + //TODO error + } } } else { //TODO make selection of updated - if (mDataManager.updateBeacon(beacon)) { - mBeaconsAdapter.insertBeacon(beacon); - } else { - //TODO + if (!mDataManager.updateBeacon(beacon)) { + //TODO error } } } @@ -261,6 +259,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); } + @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { @@ -272,6 +271,7 @@ public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.Context @Override public boolean onContextItemSelected(MenuItem item) { + ContextMenuRecyclerView.RecyclerContextMenuInfo info = (ContextMenuRecyclerView .RecyclerContextMenuInfo) item .getMenuInfo(); @@ -286,7 +286,6 @@ public boolean onContextItemSelected(MenuItem item) { default: return super.onOptionsItemSelected(item); } - } class UndoSwipableCallback extends ItemTouchHelper.SimpleCallback { diff --git a/app/src/main/java/com/samebits/beacon/locator/viewModel/BeaconViewModel.java b/app/src/main/java/com/samebits/beacon/locator/viewModel/BeaconViewModel.java index 454a047..63e9ab4 100644 --- a/app/src/main/java/com/samebits/beacon/locator/viewModel/BeaconViewModel.java +++ b/app/src/main/java/com/samebits/beacon/locator/viewModel/BeaconViewModel.java @@ -27,7 +27,7 @@ import com.samebits.beacon.locator.R; import com.samebits.beacon.locator.model.DetectedBeacon; import com.samebits.beacon.locator.model.IManagedBeacon; -import com.samebits.beacon.locator.ui.fragment.BaseFragment; +import com.samebits.beacon.locator.ui.fragment.BeaconFragment; import com.samebits.beacon.locator.util.BeaconUtil; /** @@ -36,9 +36,9 @@ public class BeaconViewModel extends BaseObservable { protected IManagedBeacon mManagedBeacon; - protected BaseFragment mFragment; + protected BeaconFragment mFragment; - public BeaconViewModel(@NonNull BaseFragment fragment, @NonNull IManagedBeacon managedBeacon) { + public BeaconViewModel(@NonNull BeaconFragment fragment, @NonNull IManagedBeacon managedBeacon) { this.mManagedBeacon = managedBeacon; this.mFragment = fragment; } @@ -145,12 +145,12 @@ public View.OnClickListener onClickBeacon() { return new View.OnClickListener() { @Override public void onClick(View v) { - launchBeaconDetailsActivity(); + clickBeacon(); } }; } - protected void launchBeaconDetailsActivity() { + protected void clickBeacon() { // do abstract? } } diff --git a/app/src/main/java/com/samebits/beacon/locator/viewModel/DetectedBeaconViewModel.java b/app/src/main/java/com/samebits/beacon/locator/viewModel/DetectedBeaconViewModel.java index 88f5f0e..b4b4c8f 100644 --- a/app/src/main/java/com/samebits/beacon/locator/viewModel/DetectedBeaconViewModel.java +++ b/app/src/main/java/com/samebits/beacon/locator/viewModel/DetectedBeaconViewModel.java @@ -18,28 +18,22 @@ package com.samebits.beacon.locator.viewModel; -import android.content.Intent; import android.support.annotation.NonNull; import com.samebits.beacon.locator.model.IManagedBeacon; import com.samebits.beacon.locator.model.TrackedBeacon; -import com.samebits.beacon.locator.ui.activity.MainNavigationActivity; -import com.samebits.beacon.locator.ui.fragment.BaseFragment; -import com.samebits.beacon.locator.util.Constants; +import com.samebits.beacon.locator.ui.fragment.BeaconFragment; /** * Created by vitas on 19/10/15. */ public class DetectedBeaconViewModel extends BeaconViewModel { - public DetectedBeaconViewModel(@NonNull BaseFragment fragment, @NonNull IManagedBeacon managedBeacon) { + public DetectedBeaconViewModel(@NonNull BeaconFragment fragment, @NonNull IManagedBeacon managedBeacon) { super(fragment, managedBeacon); } - protected void launchBeaconDetailsActivity() { - //find better way to change fragment from scan to tracked - Intent intent = MainNavigationActivity.getStartIntent(mFragment.getActivity()); - intent.putExtra(Constants.ARG_BEACON, new TrackedBeacon(mManagedBeacon)); - mFragment.startActivity(intent); + protected void clickBeacon() { + mFragment.selectBeacon(new TrackedBeacon(mManagedBeacon)); } } diff --git a/app/src/main/java/com/samebits/beacon/locator/viewModel/TrackedBeaconViewModel.java b/app/src/main/java/com/samebits/beacon/locator/viewModel/TrackedBeaconViewModel.java index 62105b3..f32c3e1 100644 --- a/app/src/main/java/com/samebits/beacon/locator/viewModel/TrackedBeaconViewModel.java +++ b/app/src/main/java/com/samebits/beacon/locator/viewModel/TrackedBeaconViewModel.java @@ -22,7 +22,7 @@ import android.view.View; import com.samebits.beacon.locator.model.IManagedBeacon; -import com.samebits.beacon.locator.ui.fragment.BaseFragment; +import com.samebits.beacon.locator.ui.fragment.BeaconFragment; import com.samebits.beacon.locator.ui.fragment.TrackedBeaconsFragment; /** @@ -30,7 +30,7 @@ */ public class TrackedBeaconViewModel extends BeaconViewModel { - public TrackedBeaconViewModel(@NonNull BaseFragment fragment, @NonNull IManagedBeacon managedBeacon) { + public TrackedBeaconViewModel(@NonNull BeaconFragment fragment, @NonNull IManagedBeacon managedBeacon) { super(fragment, managedBeacon); } diff --git a/build.gradle b/build.gradle index ee9a47a..2aa68c1 100644 --- a/build.gradle +++ b/build.gradle @@ -3,15 +3,17 @@ buildscript { repositories { jcenter() + maven { url 'https://maven.google.com' } } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.0.0' } } allprojects { repositories { jcenter() + maven { url 'https://maven.google.com' } } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 51991b7..9e4f835 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Apr 13 09:45:37 CEST 2017 +#Sat Oct 28 11:20:15 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip