-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Event<T> with possibility of one-time use, added ActivityWithou…
…tVM,
- Loading branch information
Showing
7 changed files
with
117 additions
and
83 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
mvvmBaseLib/src/main/java/io/github/luteoos/mvvmbaselib/BaseActivityMVVMWithoutVM.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.github.luteoos.mvvmbaselib | ||
|
||
import android.content.Context | ||
import android.content.pm.ActivityInfo | ||
import android.net.ConnectivityManager | ||
import android.os.Bundle | ||
import android.view.inputmethod.InputMethodManager | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
||
abstract class BaseActivityMVVMWithoutVM : AppCompatActivity() { | ||
|
||
/** | ||
* override and set layoutId here | ||
*/ | ||
abstract fun getLayoutID(): Int | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(getLayoutID()) | ||
} | ||
|
||
/** | ||
* true to portrait <-> default | ||
* false to landscape | ||
*/ | ||
fun setPortraitOrientation(isPortrait: Boolean = true) { | ||
requestedOrientation = when(isPortrait){ | ||
true -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT | ||
false -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE | ||
} | ||
} | ||
|
||
/** | ||
* cal for hide keyboard from this activity | ||
*/ | ||
fun hideKeyboard(){ | ||
if(this.currentFocus != null){ | ||
val inputMng = this.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | ||
inputMng.hideSoftInputFromWindow(this.currentFocus!!.windowToken, 0) | ||
} | ||
} | ||
|
||
/** | ||
* check if network connection is possible | ||
*/ | ||
val isNetworkOnLine: Boolean | ||
get(){ | ||
val activeNetInf = (getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager) | ||
.activeNetworkInfo | ||
return activeNetInf != null && activeNetInf.isConnected | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
mvvmBaseLib/src/main/java/io/github/luteoos/mvvmbaselib/Event.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.github.luteoos.mvvmbaselib | ||
|
||
/** | ||
* Base class for single use Events | ||
* | ||
* Created by Luteoos on 24.01.2020 | ||
*/ | ||
open class Event<out T>(private val payload: T) { | ||
|
||
/** | ||
* lock external write | ||
*/ | ||
var isUsed = false | ||
private set | ||
|
||
/** | ||
* return payload and marks as used | ||
*/ | ||
fun get(): T? = | ||
when(isUsed){ | ||
true -> null | ||
false -> {isUsed = true; payload} | ||
} | ||
|
||
/** | ||
* return payload ignoring isUsed | ||
*/ | ||
fun peek() = payload | ||
} |