Skip to content

Commit

Permalink
Android - #22, Misc
Browse files Browse the repository at this point in the history
- Begun, the overhaul has
- Adding state variables into the Activity itself
    - This allows for custom setters which automagically trigger state updates for the other views
- new LayoutState encompasses the primary 'states' the main view can find itself  in
- Removed unnecessary code from MainViewAdapter

- Added 'unknown save error' flashbar generator (found in Remote model)
- Added 'generic coming soon' flashbar generator (found in ActivityExt utils)
  • Loading branch information
MattS8 committed Aug 24, 2019
1 parent 5d1ecf5 commit 052d36a
Show file tree
Hide file tree
Showing 9 changed files with 1,211 additions and 495 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,33 @@ import com.ms8.smartirhub.android.R
import com.ms8.smartirhub.android.main_view.fragments.MainFragment

class MainViewAdapter(fm: FragmentManager, behavior: Int, private var navPosition: Int, private var baseItemId: Long) : FragmentPagerAdapter(fm, behavior) {
private var commandsFragList: MutableList<MainFragment> = ArrayList()
private var remotesFragList: MutableList<MainFragment> = ArrayList()
private var devicesFragList: MutableList<MainFragment> = ArrayList()

@SuppressLint("LogNotTimber")
override fun getItem(position: Int): Fragment {
return when (navPosition) {
R.id.navigation_commands -> commandsFragList[position].newInstance()
MainViewActivity.FP_MY_DEVICES -> devicesFragList[position].newInstance()
MainViewActivity.FP_MY_REMOTES -> remotesFragList[position].newInstance()
else -> {
Log.w("MainViewAdapter", "Unknown navigation position: $navPosition")
commandsFragList[0].newInstance()
remotesFragList[0].newInstance()
}
}
}

@SuppressLint("LogNotTimber")
override fun getCount() =
when (navPosition) {
R.id.navigation_commands -> commandsFragList.size
MainViewActivity.FP_MY_DEVICES -> devicesFragList.size
MainViewActivity.FP_MY_REMOTES -> remotesFragList.size
else -> {
Log.w("MainViewAdapter", "Unknown navigation position: $navPosition")
0
override fun getCount() : Int {
return when (navPosition) {
MainViewActivity.FP_MY_DEVICES -> { devicesFragList.size }
MainViewActivity.FP_MY_REMOTES -> { remotesFragList.size }
else -> {
Log.w("MainViewAdapter", "Unknown navigation position: $navPosition")
0
}
}
}


override fun getItemPosition(`object`: Any): Int {
return PagerAdapter.POSITION_NONE
}
Expand All @@ -49,26 +47,25 @@ class MainViewAdapter(fm: FragmentManager, behavior: Int, private var navPositio

fun addFragment(fragment: MainFragment, list : ViewPagerList) {
when (list) {
Companion.ViewPagerList.COMMANDS -> commandsFragList.add(fragment)
Companion.ViewPagerList.REMOTES -> remotesFragList.add(fragment)
Companion.ViewPagerList.DEVICES -> devicesFragList.add(fragment)
}
}

fun setNavPosition(navPosition: Int) {
baseItemId += when (this.navPosition) {
R.id.navigation_commands -> commandsFragList.size
MainViewActivity.FP_MY_DEVICES -> devicesFragList.size
MainViewActivity.FP_MY_REMOTES -> remotesFragList.size
else -> maxOf(commandsFragList.size, devicesFragList.size, remotesFragList.size)
else -> maxOf(devicesFragList.size, remotesFragList.size)
}
this.navPosition = navPosition

notifyDataSetChanged()
}

fun getBaseItemId(): Long = baseItemId

companion object {
enum class ViewPagerList {COMMANDS, REMOTES, DEVICES}
enum class ViewPagerList {REMOTES, DEVICES}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,134 @@
package com.ms8.smartirhub.android.main_view.views

class MainViewFAB {
import android.content.Context
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.util.Log
import androidx.core.content.ContextCompat
import androidx.vectordrawable.graphics.drawable.Animatable2Compat
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.ms8.smartirhub.android.R
import com.ms8.smartirhub.android.database.AppState
import com.ms8.smartirhub.android.main_view.MainViewActivity
import com.ms8.smartirhub.android.main_view.MainViewActivity.Companion.LayoutState
import com.ms8.smartirhub.android.utils.extensions.getGenericComingSoonFlashbar

class MainViewFAB(context: Context, attrs: AttributeSet) : FloatingActionButton(context, attrs) {

/*
----------------------------------------------
State Variables
----------------------------------------------
*/
var layoutState : LayoutState? = null
set(value) {
field = value
applyLayoutState()
}

var isListeningForSaveRemoteConfirmation : Boolean = false
set(value) {
field = value
applyLayoutState()
}


fun applyLayoutState() {
when (layoutState) {
LayoutState.REMOTES_FAV ->
{
if (AppState.tempData.tempRemoteProfile.uid == "") {
// show 'create remote' icon
setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_new_remote_icon))
imageTintList = ContextCompat.getColorStateList(context, R.color.black)

// set click listener to 'create remote'
setOnClickListener{(context as MainViewActivity).createRemote() }

} else {
// show 'edit remote' icon
setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_mode_edit_black_24dp))
imageTintList = ContextCompat.getColorStateList(context, R.color.black)

// set click listener to 'edit remote'
setOnClickListener { (context as MainViewActivity).editRemote() }
}
}
LayoutState.REMOTES_FAV_EDITING ->
{
if (isListeningForSaveRemoteConfirmation) {
// show 'saving' icon
val animatedDrawable = AnimatedVectorDrawableCompat.create(context, R.drawable.edit_to_save)
?.apply {
registerAnimationCallback(object : Animatable2Compat.AnimationCallback() {
override fun onAnimationEnd(drawable: Drawable?) {
val savingDrawable = AnimatedVectorDrawableCompat.create(context, R.drawable.remote_saving)
?.apply {
registerAnimationCallback(object : Animatable2Compat.AnimationCallback() {
override fun onAnimationEnd(drawable: Drawable?) {
post { start() }
}
})
}
if (layoutState == LayoutState.REMOTES_FAV_EDITING && isListeningForSaveRemoteConfirmation) {
setImageDrawable(savingDrawable)
imageTintList = ContextCompat.getColorStateList(context, R.color.black)
savingDrawable?.start()
}
}
})
}
setImageDrawable(animatedDrawable)
animatedDrawable?.start()

// remove click listener
setOnClickListener { }
} else {
// show 'save edits' icon
setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_done_green_24dp))
imageTintList = ContextCompat.getColorStateList(context, R.color.md_green_300)

// set click listener to 'save remote'
setOnClickListener { (context as MainViewActivity).saveRemote() }
}
}
LayoutState.REMOTES_ALL ->
{
// show 'create remote' icon
setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_new_remote_icon))
imageTintList = ContextCompat.getColorStateList(context, R.color.black)

// set click listener to 'create remote' AND page to VP position 0
setOnClickListener {
(context as MainViewActivity).let {
it.switchInnerPage(0)
it.createRemote()
}
}
}
LayoutState.DEVICES_HUBS ->
{
// show 'add hub' icon
setImageDrawable(ContextCompat.getDrawable(context, R.drawable.nav_new_hub))
imageTintList = ContextCompat.getColorStateList(context, R.color.black)

//todo set click listener to 'add hub'
setOnClickListener {
(context as MainViewActivity).getGenericComingSoonFlashbar().build().show()
}
}
LayoutState.DEVICES_ALL ->
{
// show 'add hub' icon
setImageDrawable(ContextCompat.getDrawable(context, R.drawable.nav_new_device))
imageTintList = ContextCompat.getColorStateList(context, R.color.black)

//todo set click listener to 'add hub'
setOnClickListener {
(context as MainViewActivity).getGenericComingSoonFlashbar().build().show()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,6 @@ fun AppCompatActivity.getRemoteNameErrorString() : String {
return "${getString(R.string.remote_names_must_be)} ${MyValidators.MIN_REMOTE_NAME_LENGTH} - ${MyValidators.MAX_REMOTE_NAME_LENGTH} ${getString(R.string.and_no_characters)}"
}




fun AppCompatActivity?.showRemoteNameEmptyFlashbar() {
this?.let {
getGenericErrorFlashbar(true)
Expand All @@ -412,3 +409,12 @@ fun AppCompatActivity?.showInvalidRemoteNameFlashbar() {
}
}

fun AppCompatActivity?.showUnknownRemoteSaveError() {
this?.let {
getGenericErrorFlashbar(true)
.message(getString(R.string.err_unknown_save_remote))
.build()
.show()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,12 @@ fun AppCompatActivity.getGenericErrorFlashbar(showPositiveAction : Boolean = fal
}
}

fun AppCompatActivity.getGenericComingSoonFlashbar() = Flashbar.Builder(this)
.gravity(Flashbar.Gravity.BOTTOM)
.showOverlay()
.backgroundColorRes(R.color.colorCardDark)
.messageColorRes(R.color.md_yellow_A100)
.enableSwipeToDismiss()
.dismissOnTapOutside()
.duration(Flashbar.DURATION_LONG)

27 changes: 24 additions & 3 deletions android/SmartIRHub/app/src/main/res/drawable/nav_new_device.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

</selector>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="vector"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:name="path"
android:pathData="M 17 16 L 13 12 L 13 8.82 C 14.16 8.4 15 7.3 15 6 C 15 4.34 13.66 3 12 3 C 10.34 3 9 4.34 9 6 C 9 7.3 9.84 8.4 11 8.82 L 11 12 L 7 16 L 3 16 L 3 21 L 8 21 L 8 17.95 L 12 13.75 L 16 17.95 L 16 21 L 21 21 L 21 16 L 17 16 Z"
android:fillColor="#000000"
android:strokeAlpha="0"/>
<path
android:name="path_1"
android:pathData="M 19.007 8.542 L 19.007 2.623 L 21 2.623 L 21 8.542 Z"
android:fillColor="#000000"
android:strokeAlpha="0"
android:strokeWidth="0.1"/>
<path
android:name="path_2"
android:pathData="M 17.011 6.593 L 17.011 4.572 L 23.018 4.572 L 23.018 6.593 Z"
android:fillColor="#000000"
android:strokeWidth="0.1"/>
</vector>
62 changes: 60 additions & 2 deletions android/SmartIRHub/app/src/main/res/drawable/nav_new_hub.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="vector"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:name="path"
android:pathData="M 3.176 19.343 C 3.176 19.086 2.945 11.273 3.251 11.566 C 3.379 11.688 2.983 16.445 3.275 18.563 C 3.45 19.828 4.753 20.327 4.888 20.378 C 6.487 20.984 9.347 21.195 11.93 21.195 C 14.462 21.195 18.094 20.986 19.707 20.27 C 20.224 20.04 20.299 19.995 20.515 19.659 C 20.722 19.334 20.538 11.452 20.717 11.603 C 20.886 11.745 20.749 19.19 20.749 19.343 C 20.749 19.886 19.751 20.452 17.963 20.788 C 16.406 21.08 14.221 21.179 11.963 21.179 C 7.11 21.179 3.176 20.357 3.176 19.343 Z"
android:fillColor="#000000"
android:fillAlpha="0"
android:strokeColor="#000000"
android:strokeWidth="1.5"/>
<path
android:name="path_1"
android:pathData="M 3.177 11.566 C 3.177 10.552 7.11 9.729 11.963 9.729 C 16.816 9.729 20.749 10.552 20.749 11.566 C 20.749 12.58 16.816 13.401 11.963 13.401 C 7.11 13.401 3.177 12.58 3.177 11.566 Z"
android:fillColor="#000000"
android:fillAlpha="0"
android:strokeColor="#000000"
android:strokeWidth="1.5"/>
<path
android:name="path_2"
android:pathData="M 3.751 12.921 C 3.751 12.921 11.798 32.459 20.132 12.484"
android:fillColor="#D8D8D8"
android:fillAlpha="0"
android:strokeColor="#000000"
android:strokeWidth="1"/>
<path
android:name="path_3"
android:pathData="M 19.007 8.542 L 19.007 2.623 L 21 2.623 L 21 8.542 Z"
android:fillColor="#000000"/>
<path
android:name="path_4"
android:pathData="M 17.011 6.593 L 17.011 4.572 L 23.018 4.572 L 23.018 6.593 Z"
android:fillColor="#000000"/>
<path
android:name="path_5"
android:pathData="M 13.172 16.981 C 13.172 16.398 12.648 15.926 12.001 15.926 C 11.352 15.926 10.828 16.398 10.828 16.981 C 10.828 17.563 11.352 18.035 12.001 18.035 C 12.648 18.035 13.172 17.563 13.172 16.981 Z"
android:fillColor="#000000"
android:fillAlpha="0"
android:strokeColor="#000000"
android:strokeWidth="0.8"/>
<path
android:name="path_6"
android:pathData="M 15.59 21.158 L 16 19.751 C 16 19.751 17.905 17.318 17.934 17.201 L 19.37 14.125 L 19.985 13.509 C 19.985 13.509 20.864 15.15 20.835 15.355 C 20.835 15.355 20.453 19.398 20.366 19.604 Z"
android:fillColor="#000000"
android:strokeColor="#979797"
android:strokeAlpha="0"
android:strokeWidth="0.1"/>
<path
android:name="path_7"
android:pathData="M 8.322 20.952 L 8.205 19.546 L 6.945 18.227 L 5.48 15.971 L 4.161 13.978 C 4.161 13.978 3.458 13.919 3.458 14.125 C 3.458 14.125 3.312 16.849 3.341 16.996 C 3.341 16.996 4.073 19.458 4.132 19.487 C 4.132 19.487 6.418 20.924 6.476 20.894 Z"
android:fillColor="#000000"
android:strokeColor="#000000"
android:strokeAlpha="0"
android:strokeWidth="0.1"/>
</vector>



</selector>
2 changes: 2 additions & 0 deletions android/SmartIRHub/app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

<dimen name="btn_corner_radius">24dp</dimen>
<dimen name="rmt_corner_radius">32dp</dimen>
<dimen name="toolbar_horizontal_margin_remote">32dp</dimen>
<dimen name="toolbar_horizontal_margin">12dp</dimen>
</resources>
2 changes: 1 addition & 1 deletion android/SmartIRHub/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
<string name="create_from">Create from</string>
<string name="device_template">Device Template</string>
<string name="existing_remote">Existing Remote</string>
<string name="blank_layout">Black Layout</string>
<string name="blank_layout">Blank Layout</string>
<string name="must_be_between">Must be between</string>
<string name="and_no_characters">characters and contain no special characters</string>
<string name="pasasword_length_must_be">Password length must be</string>
Expand Down

0 comments on commit 052d36a

Please sign in to comment.