├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── motion.xml │ │ │ │ ├── colors.xml │ │ │ │ └── themes.xml │ │ │ ├── values-night │ │ │ │ ├── colors.xml │ │ │ │ └── themes.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable │ │ │ │ ├── ic_add_24.xml │ │ │ │ ├── ic_baseline_code_36.xml │ │ │ │ ├── ic_baseline_timer_36.xml │ │ │ │ ├── ic_outline_cloud_upload_24.xml │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── layout │ │ │ │ ├── fragment_history.xml │ │ │ │ ├── activity_main.xml │ │ │ │ ├── item_history.xml │ │ │ │ ├── fragment_add_paste.xml │ │ │ │ └── fragment_view_paste.xml │ │ │ ├── navigation │ │ │ │ └── nav_graph.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── kriticalflare │ │ │ │ └── nativbin │ │ │ │ ├── di │ │ │ │ ├── BaseViewModel.kt │ │ │ │ ├── ViewModelKey.kt │ │ │ │ ├── MvRxModule.kt │ │ │ │ ├── DatabaseModule.kt │ │ │ │ ├── DaggerMvRxViewModelFactory.kt │ │ │ │ └── AssistedViewModelFactory.kt │ │ │ │ ├── history │ │ │ │ ├── data │ │ │ │ │ ├── HistoryDatabase.kt │ │ │ │ │ ├── ViewedPaste.kt │ │ │ │ │ ├── HistoryRepository.kt │ │ │ │ │ └── HistoryDao.kt │ │ │ │ ├── HistoryViewState.kt │ │ │ │ ├── HistoryController.kt │ │ │ │ ├── HistoryViewModel.kt │ │ │ │ ├── HistoryFragment.kt │ │ │ │ └── EpoxyHistoryModel.kt │ │ │ │ ├── MitbinApp.kt │ │ │ │ ├── utils │ │ │ │ ├── TimeUtils.kt │ │ │ │ ├── PowerMenuUtils.kt │ │ │ │ └── Event.kt │ │ │ │ ├── addPaste │ │ │ │ ├── AddPasteViewModel.kt │ │ │ │ └── AddPasteFragment.kt │ │ │ │ ├── MainActivity.kt │ │ │ │ └── viewPaste │ │ │ │ ├── ViewPasteViewModel.kt │ │ │ │ └── ViewPasteFragment.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── kriticalflare │ │ │ └── nativbin │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── kriticalflare │ │ └── nativbin │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── bin-wrapper ├── .gitignore ├── src │ └── main │ │ └── java │ │ └── com │ │ └── kriticalflare │ │ └── bin_wrapper │ │ ├── data │ │ ├── Repository.kt │ │ └── PasteRepository.kt │ │ ├── remote │ │ ├── model │ │ │ ├── UploadPaste.kt │ │ │ └── Paste.kt │ │ ├── MitBinService.kt │ │ └── MitBinServiceBuilder.kt │ │ └── BinWrapper.kt └── build.gradle ├── .idea ├── .name ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── vcs.xml ├── compiler.xml ├── misc.xml ├── runConfigurations.xml ├── gradle.xml └── jarRepositories.xml ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── .gitignore ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /bin-wrapper/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Mitbin-client-native -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':bin-wrapper' 2 | include ':app' 3 | rootProject.name = "Mitbin-client-native" -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriticalflare/Mitbin-Client-native/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriticalflare/Mitbin-Client-native/master/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriticalflare/Mitbin-Client-native/master/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriticalflare/Mitbin-Client-native/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriticalflare/Mitbin-Client-native/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriticalflare/Mitbin-Client-native/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriticalflare/Mitbin-Client-native/master/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriticalflare/Mitbin-Client-native/master/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriticalflare/Mitbin-Client-native/master/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriticalflare/Mitbin-Client-native/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriticalflare/Mitbin-Client-native/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Mitbin-client-native 3 | 4 | Hello blank fragment 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mitbin-Client-native 2 | 3 | A [Mitbin](https://mitbin.herokuapp.com/) Client in native android 4 | 5 | ### Functionality 6 | * Getting and viewing pastes 7 | * Adding new pastes 8 | * Deeplink [Mitbin](https://mitbin.herokuapp.com) links into the app 9 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFF 4 | #35363A 5 | #424242 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/motion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 300 4 | 225 5 | 175 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 14 17:14:37 IST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/di/BaseViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.di 2 | 3 | import com.airbnb.mvrx.MavericksState 4 | import com.airbnb.mvrx.MavericksViewModel 5 | 6 | abstract class BaseViewModel(initialState: S) : MavericksViewModel(initialState) -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/history/data/HistoryDatabase.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.history.data 2 | 3 | import androidx.room.Database 4 | import androidx.room.RoomDatabase 5 | 6 | @Database(entities = [ViewedPaste::class], version = 1, exportSchema = false) 7 | abstract class HistoryDatabase : RoomDatabase() { 8 | 9 | abstract fun historyDao(): HistoryDao 10 | } -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/history/HistoryViewState.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.history 2 | 3 | import com.airbnb.mvrx.Async 4 | import com.airbnb.mvrx.MavericksState 5 | import com.airbnb.mvrx.Uninitialized 6 | import com.kriticalflare.nativbin.history.data.ViewedPaste 7 | 8 | data class HistoryViewState(val historyList: Async> = Uninitialized): MavericksState -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/history/data/ViewedPaste.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.history.data 2 | 3 | import androidx.room.Entity 4 | import androidx.room.PrimaryKey 5 | 6 | @Entity 7 | data class ViewedPaste( 8 | @PrimaryKey 9 | val name: String, 10 | val content: String, 11 | val language: String, 12 | val createdAt: String, 13 | val expiresAt: String 14 | ) -------------------------------------------------------------------------------- /bin-wrapper/src/main/java/com/kriticalflare/bin_wrapper/data/Repository.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.bin_wrapper.data 2 | 3 | import com.kriticalflare.bin_wrapper.remote.model.Paste 4 | import com.kriticalflare.bin_wrapper.remote.model.UploadPaste 5 | 6 | interface Repository { 7 | 8 | suspend fun getPaste(name: String): List 9 | 10 | suspend fun addPaste(paste: UploadPaste): PasteResponse 11 | } -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/MitbinApp.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin 2 | 3 | import android.app.Application 4 | import com.airbnb.mvrx.Mavericks 5 | import dagger.hilt.android.HiltAndroidApp 6 | 7 | @HiltAndroidApp 8 | class MitbinApp : Application() { 9 | 10 | override fun onCreate() { 11 | super.onCreate() 12 | Mavericks.initialize(debugMode = true) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/di/ViewModelKey.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.di 2 | 3 | import dagger.MapKey 4 | import kotlin.reflect.KClass 5 | 6 | /** 7 | * A [MapKey] for populating a map of ViewModels and their factories. 8 | */ 9 | @Retention(AnnotationRetention.RUNTIME) 10 | @Target(AnnotationTarget.FUNCTION) 11 | @MapKey 12 | annotation class ViewModelKey(val value: KClass>) -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_add_24.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_code_36.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/test/java/com/kriticalflare/nativbin/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/utils/TimeUtils.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.utils 2 | 3 | 4 | 5 | fun TimeInMinutes(duration: String): Int { 6 | return when (duration) { 7 | "One day" -> { 8 | 1440 9 | } 10 | "One week" -> { 11 | 10080 12 | } 13 | "One month" -> { 14 | // 30 days 15 | 43200 16 | } 17 | else -> { 18 | throw Throwable("Invalid Duration") 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_history.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/history/data/HistoryRepository.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.history.data 2 | 3 | import androidx.lifecycle.LiveData 4 | import kotlinx.coroutines.flow.Flow 5 | import javax.inject.Inject 6 | 7 | class HistoryRepository @Inject constructor(val dao: HistoryDao) { 8 | suspend fun insertViewedPaste(viewedPaste: ViewedPaste) { 9 | dao.insert(viewedPaste) 10 | } 11 | 12 | fun getViewedPastes(): Flow> { 13 | return dao.getHistory() 14 | } 15 | } -------------------------------------------------------------------------------- /bin-wrapper/src/main/java/com/kriticalflare/bin_wrapper/remote/model/UploadPaste.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.bin_wrapper.remote.model 2 | 3 | import com.squareup.moshi.Json 4 | import com.squareup.moshi.JsonClass 5 | 6 | @JsonClass(generateAdapter = true) 7 | data class UploadPaste( 8 | @Json(name = "name") 9 | val name: String, 10 | @Json(name = "content") 11 | val content: String, 12 | @Json(name = "language") 13 | val language: String, 14 | @Json(name = "expiresInMinutes") 15 | val expiresInMinutes: Int 16 | ) -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/utils/PowerMenuUtils.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.utils 2 | 3 | 4 | fun String.formatLanguageApi(): String{ 5 | return when (this) { 6 | "Plain Text" -> { 7 | this 8 | } 9 | "Python" -> { 10 | "python" 11 | } 12 | "Json" -> { 13 | "json" 14 | } 15 | "C Like" -> { 16 | "clike" 17 | } 18 | else -> { 19 | throw Throwable("Invalid language") 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /bin-wrapper/src/main/java/com/kriticalflare/bin_wrapper/remote/model/Paste.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.bin_wrapper.remote.model 2 | 3 | 4 | import com.squareup.moshi.Json 5 | import com.squareup.moshi.JsonClass 6 | 7 | @JsonClass(generateAdapter = true) 8 | data class Paste( 9 | @Json(name = "name") 10 | val name: String, 11 | @Json(name = "content") 12 | val content: String, 13 | @Json(name = "language") 14 | val language: String, 15 | @Json(name = "createdAt") 16 | val createdAt: String, 17 | @Json(name = "expiresAt") 18 | val expiresAt: String 19 | ) -------------------------------------------------------------------------------- /bin-wrapper/src/main/java/com/kriticalflare/bin_wrapper/remote/MitBinService.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.bin_wrapper.remote 2 | 3 | import com.kriticalflare.bin_wrapper.remote.model.Paste 4 | import com.kriticalflare.bin_wrapper.remote.model.UploadPaste 5 | import retrofit2.http.Body 6 | import retrofit2.http.GET 7 | import retrofit2.http.POST 8 | import retrofit2.http.Query 9 | 10 | interface MitBinService { 11 | 12 | @GET("paste") 13 | suspend fun getPaste(@Query("name") name: String): List 14 | 15 | @POST("paste") 16 | suspend fun addPaste(@Body paste: UploadPaste): Paste 17 | } -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | @color/black 11 | @color/white 12 | @color/white 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_timer_36.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/history/data/HistoryDao.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.history.data 2 | 3 | import androidx.room.Dao 4 | import androidx.room.Insert 5 | import androidx.room.OnConflictStrategy 6 | import androidx.room.Query 7 | import kotlinx.coroutines.flow.Flow 8 | 9 | @Dao 10 | interface HistoryDao { 11 | @Query("SELECT * FROM viewedpaste") 12 | fun getHistory(): Flow> 13 | 14 | @Insert(onConflict = OnConflictStrategy.REPLACE) 15 | suspend fun insert(viewedPaste: ViewedPaste) 16 | 17 | @Query("DELETE FROM viewedpaste") 18 | suspend fun delete() 19 | } -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/di/MvRxModule.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.di 2 | 3 | import com.kriticalflare.nativbin.history.HistoryViewModel 4 | import com.squareup.inject.assisted.dagger2.AssistedModule 5 | import dagger.Binds 6 | import dagger.Module 7 | import dagger.hilt.InstallIn 8 | import dagger.hilt.android.components.ApplicationComponent 9 | import dagger.multibindings.IntoMap 10 | 11 | @AssistedModule 12 | @InstallIn(ApplicationComponent::class) 13 | @Module 14 | interface MvRxModule { 15 | 16 | @Binds 17 | @IntoMap 18 | @ViewModelKey(HistoryViewModel::class) 19 | fun historyViewModelFactory(factory: HistoryViewModel.Factory): AssistedViewModelFactory<*, *> 20 | } -------------------------------------------------------------------------------- /bin-wrapper/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | apply plugin: 'kotlin' 3 | apply plugin: 'kotlin-kapt' 4 | 5 | dependencies { 6 | implementation fileTree(dir: 'libs', include: ['*.jar']) 7 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 8 | implementation 'com.squareup.retrofit2:retrofit:2.9.0' 9 | implementation 'com.squareup.okhttp3:logging-interceptor:4.8.1' 10 | 11 | implementation 'com.squareup.retrofit2:converter-moshi:2.9.0' 12 | implementation "com.squareup.moshi:moshi:1.9.3" 13 | kapt "com.squareup.moshi:moshi-kotlin-codegen:1.9.3" 14 | } 15 | 16 | sourceCompatibility = JavaVersion.VERSION_1_8 17 | targetCompatibility = JavaVersion.VERSION_1_8 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_outline_cloud_upload_24.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/utils/Event.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.utils 2 | 3 | /** 4 | * Used as a wrapper for data that is exposed via a LiveData that represents an event. 5 | */ 6 | open class Event(private val content: T) { 7 | 8 | var hasBeenHandled = false 9 | private set // Allow external read but not write 10 | 11 | /** 12 | * Returns the content and prevents its use again. 13 | */ 14 | fun getContentIfNotHandled(): T? { 15 | return if (hasBeenHandled) { 16 | null 17 | } else { 18 | hasBeenHandled = true 19 | content 20 | } 21 | } 22 | 23 | /** 24 | * Returns the content, even if it's already been handled. 25 | */ 26 | fun peekContent(): T = content 27 | } -------------------------------------------------------------------------------- /bin-wrapper/src/main/java/com/kriticalflare/bin_wrapper/BinWrapper.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.bin_wrapper 2 | 3 | import com.kriticalflare.bin_wrapper.data.PasteRepository 4 | import com.kriticalflare.bin_wrapper.data.PasteResponse 5 | import com.kriticalflare.bin_wrapper.remote.MitBinServiceBuilder 6 | import com.kriticalflare.bin_wrapper.remote.model.Paste 7 | import com.kriticalflare.bin_wrapper.remote.model.UploadPaste 8 | 9 | class BinWrapper { 10 | private val pasteRepository by lazy { 11 | PasteRepository(MitBinServiceBuilder.retrofit) 12 | } 13 | 14 | suspend fun getPaste(name: String): List { 15 | return pasteRepository.getPaste(name) 16 | } 17 | 18 | suspend fun addPaste(paste: UploadPaste): PasteResponse { 19 | return pasteRepository.addPaste(paste) 20 | } 21 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/kriticalflare/nativbin/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.kriticalflare.nativbin", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /bin-wrapper/src/main/java/com/kriticalflare/bin_wrapper/data/PasteRepository.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.bin_wrapper.data 2 | 3 | import com.kriticalflare.bin_wrapper.remote.MitBinService 4 | import com.kriticalflare.bin_wrapper.remote.model.Paste 5 | import com.kriticalflare.bin_wrapper.remote.model.UploadPaste 6 | 7 | class PasteRepository(private val pasteService: MitBinService): Repository { 8 | 9 | override suspend fun getPaste(name: String): List = pasteService.getPaste(name) 10 | 11 | override suspend fun addPaste(paste: UploadPaste): PasteResponse { 12 | return try { 13 | pasteService.addPaste(paste) 14 | PasteResponse.Success 15 | } catch (t: Throwable){ 16 | PasteResponse.Failure(t.message ?: "Try again error later") 17 | } 18 | } 19 | 20 | } 21 | 22 | sealed class PasteResponse { 23 | object Success: PasteResponse() 24 | class Failure(val message: String): PasteResponse() 25 | } 26 | 27 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/history/HistoryController.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.history 2 | 3 | import android.widget.Toast 4 | import com.airbnb.epoxy.EpoxyController 5 | import com.kriticalflare.nativbin.history.data.ViewedPaste 6 | 7 | class HistoryController : EpoxyController() { 8 | 9 | var allViewedPaste: List = emptyList() 10 | set(value) { 11 | field = value 12 | requestModelBuild() 13 | } 14 | 15 | override fun buildModels() { 16 | history { 17 | id("1") 18 | name("Test") 19 | } 20 | allViewedPaste.forEach { 21 | history { 22 | id(it.name) 23 | name(it.name) 24 | language(it.language) 25 | cardOnClick { model, parentView, clickedView, position -> 26 | Toast.makeText(parentView.cardView.context, "$position", Toast.LENGTH_LONG).show() 27 | } 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | -------------------------------------------------------------------------------- /bin-wrapper/src/main/java/com/kriticalflare/bin_wrapper/remote/MitBinServiceBuilder.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.bin_wrapper.remote 2 | 3 | import okhttp3.OkHttpClient 4 | import okhttp3.logging.HttpLoggingInterceptor 5 | import retrofit2.Retrofit 6 | import retrofit2.converter.moshi.MoshiConverterFactory 7 | import java.util.concurrent.TimeUnit 8 | 9 | object MitBinServiceBuilder { 10 | val retrofit: MitBinService by lazy { 11 | Retrofit.Builder() 12 | .client( 13 | OkHttpClient.Builder() 14 | .addInterceptor(HttpLoggingInterceptor().apply { 15 | level = HttpLoggingInterceptor.Level.BODY 16 | }) 17 | .connectTimeout(30, TimeUnit.SECONDS) 18 | .readTimeout(30, TimeUnit.SECONDS) 19 | .writeTimeout(30, TimeUnit.SECONDS) 20 | .build() 21 | ) 22 | .addConverterFactory(MoshiConverterFactory.create()) 23 | .baseUrl("https://mitbin.herokuapp.com/api/") 24 | .build().create(MitBinService::class.java); 25 | } 26 | } -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/addPaste/AddPasteViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.addPaste 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.lifecycle.MutableLiveData 5 | import androidx.lifecycle.ViewModel 6 | import androidx.lifecycle.viewModelScope 7 | import com.kriticalflare.bin_wrapper.BinWrapper 8 | import com.kriticalflare.bin_wrapper.data.PasteResponse 9 | import com.kriticalflare.bin_wrapper.remote.model.Paste 10 | import com.kriticalflare.bin_wrapper.remote.model.UploadPaste 11 | import com.kriticalflare.nativbin.utils.Event 12 | import kotlinx.coroutines.launch 13 | 14 | class AddPasteViewModel: ViewModel(){ 15 | private val binWrapper = BinWrapper() 16 | 17 | private val _uploadStatus = MutableLiveData>() 18 | 19 | val uploadStatus : LiveData> 20 | get() = _uploadStatus 21 | 22 | 23 | fun uploadPaste(paste: UploadPaste){ 24 | println(paste) 25 | viewModelScope.launch { 26 | _uploadStatus.value = Event(binWrapper.addPaste(paste)) 27 | println(_uploadStatus.value) 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/di/DatabaseModule.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.di 2 | 3 | import android.content.Context 4 | import androidx.room.Room 5 | import com.kriticalflare.nativbin.history.data.HistoryDao 6 | import com.kriticalflare.nativbin.history.data.HistoryDatabase 7 | import dagger.Module 8 | import dagger.Provides 9 | import dagger.hilt.InstallIn 10 | import dagger.hilt.android.components.ApplicationComponent 11 | import dagger.hilt.android.qualifiers.ApplicationContext 12 | import dagger.hilt.migration.DisableInstallInCheck 13 | import javax.inject.Singleton 14 | 15 | @Module 16 | @DisableInstallInCheck 17 | @InstallIn(ApplicationComponent::class) 18 | class DatabaseModule { 19 | @Singleton 20 | @Provides 21 | fun providesHistoryDatabase(@ApplicationContext appContext: Context): HistoryDatabase { 22 | return Room.databaseBuilder( 23 | appContext, 24 | HistoryDatabase::class.java, 25 | "History_Database" 26 | ).build() 27 | } 28 | 29 | @Provides 30 | fun providesHistoryDao(historyDatabase: HistoryDatabase): HistoryDao { 31 | return historyDatabase.historyDao() 32 | } 33 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/history/HistoryViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.history 2 | 3 | import android.util.Log 4 | import com.airbnb.mvrx.* 5 | import com.kriticalflare.nativbin.di.AssistedViewModelFactory 6 | import com.kriticalflare.nativbin.di.BaseViewModel 7 | import com.kriticalflare.nativbin.di.DaggerMvRxViewModelFactory 8 | import com.kriticalflare.nativbin.history.data.HistoryRepository 9 | import com.squareup.inject.assisted.Assisted 10 | import com.squareup.inject.assisted.AssistedInject 11 | import kotlinx.coroutines.flow.collect 12 | import kotlinx.coroutines.launch 13 | 14 | class HistoryViewModel @AssistedInject constructor( 15 | @Assisted initialState: HistoryViewState, 16 | private val historyRepository: HistoryRepository 17 | ) : BaseViewModel(initialState = initialState) { 18 | 19 | init { 20 | fetchHistory() 21 | } 22 | 23 | private fun fetchHistory() = withState { 24 | viewModelScope.launch { 25 | historyRepository.getViewedPastes().execute { 26 | copy(historyList = it) 27 | } 28 | Log.d("vm4", "$it") 29 | } 30 | } 31 | 32 | @AssistedInject.Factory 33 | interface Factory : AssistedViewModelFactory { 34 | override fun create(initialState: HistoryViewState): HistoryViewModel 35 | } 36 | 37 | companion object : DaggerMvRxViewModelFactory(HistoryViewModel::class.java) 38 | } -------------------------------------------------------------------------------- /app/src/main/res/navigation/nav_graph.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 17 | 20 | 23 | 24 | 29 | 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/history/HistoryFragment.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.history 2 | 3 | import android.os.Bundle 4 | import androidx.fragment.app.Fragment 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import android.widget.Toast 9 | import com.airbnb.epoxy.EpoxyController 10 | import com.airbnb.mvrx.* 11 | import com.kriticalflare.nativbin.databinding.FragmentHistoryBinding 12 | 13 | class HistoryFragment : Fragment(), MavericksView { 14 | 15 | private var _binding: FragmentHistoryBinding? = null 16 | private val binding get() = _binding!! 17 | 18 | private val historyViewModel: HistoryViewModel by fragmentViewModel() 19 | private val epoxyController by lazy { 20 | HistoryController() 21 | } 22 | 23 | override fun onCreateView( 24 | inflater: LayoutInflater, container: ViewGroup?, 25 | savedInstanceState: Bundle? 26 | ): View? { 27 | // Inflate the layout for this fragment 28 | _binding = FragmentHistoryBinding.inflate(inflater, container, false) 29 | binding.epoxyRecycler.setController(epoxyController) 30 | return binding.root 31 | } 32 | 33 | override fun invalidate() = withState(historyViewModel) { state -> 34 | when (state.historyList) { 35 | is Success -> { 36 | epoxyController.allViewedPaste = state.historyList.invoke() 37 | epoxyController.requestModelBuild() 38 | } 39 | else -> { 40 | 41 | } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | import android.os.Bundle 5 | import androidx.navigation.findNavController 6 | import androidx.navigation.fragment.NavHostFragment 7 | import androidx.navigation.ui.AppBarConfiguration 8 | import androidx.navigation.ui.navigateUp 9 | import androidx.navigation.ui.setupActionBarWithNavController 10 | import com.kriticalflare.nativbin.databinding.ActivityMainBinding 11 | import dagger.hilt.android.AndroidEntryPoint 12 | 13 | @AndroidEntryPoint 14 | class MainActivity : AppCompatActivity() { 15 | 16 | private lateinit var binding: ActivityMainBinding 17 | private lateinit var appBarConfiguration: AppBarConfiguration 18 | 19 | override fun onCreate(savedInstanceState: Bundle?) { 20 | super.onCreate(savedInstanceState) 21 | binding = ActivityMainBinding.inflate(layoutInflater) 22 | val view = binding.root 23 | setContentView(view) 24 | 25 | val navHostFragment = 26 | supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment 27 | val navController = navHostFragment.navController 28 | appBarConfiguration = AppBarConfiguration(navController.graph) 29 | setupActionBarWithNavController(navController, appBarConfiguration) 30 | 31 | } 32 | 33 | override fun onSupportNavigateUp(): Boolean { 34 | val navController = findNavController(R.id.nav_host_fragment) 35 | return navController.navigateUp(appBarConfiguration) 36 | || super.onSupportNavigateUp() 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/history/EpoxyHistoryModel.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.history 2 | 3 | import android.view.View 4 | import android.widget.TextView 5 | import com.airbnb.epoxy.EpoxyAttribute 6 | import com.airbnb.epoxy.EpoxyHolder 7 | import com.airbnb.epoxy.EpoxyModelClass 8 | import com.airbnb.epoxy.EpoxyModelWithHolder 9 | import com.google.android.material.card.MaterialCardView 10 | import com.kriticalflare.nativbin.R 11 | import kotlinx.android.synthetic.main.item_history.view.* 12 | 13 | @EpoxyModelClass(layout = R.layout.item_history) 14 | abstract class HistoryModel : EpoxyModelWithHolder() { 15 | 16 | @EpoxyAttribute 17 | var name: CharSequence = "" 18 | 19 | @EpoxyAttribute 20 | var language: CharSequence = "" 21 | 22 | @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) 23 | var cardOnClick: View.OnClickListener? = null 24 | 25 | override fun bind(holder: HistoryHolder) { 26 | holder.itemName.text = name 27 | holder.itemLanguage.text = language 28 | } 29 | 30 | override fun unbind(holder: HistoryHolder) { 31 | holder.cardView.setOnClickListener(null) 32 | } 33 | 34 | inner class HistoryHolder : EpoxyHolder() { 35 | lateinit var itemName: TextView 36 | lateinit var cardView: MaterialCardView 37 | lateinit var itemLanguage: TextView 38 | 39 | override fun bindView(itemView: View) { 40 | itemName = itemView.paste_name 41 | itemLanguage = itemView.paste_language 42 | cardView = itemView.history_card 43 | cardView.setOnClickListener(cardOnClick) 44 | } 45 | 46 | } 47 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_history.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 16 | 25 | 26 | 33 | 34 | 41 | 42 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/di/DaggerMvRxViewModelFactory.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.di 2 | 3 | import androidx.fragment.app.FragmentActivity 4 | import com.airbnb.mvrx.* 5 | import dagger.hilt.EntryPoint 6 | import dagger.hilt.EntryPoints 7 | import dagger.hilt.InstallIn 8 | import dagger.hilt.android.components.ApplicationComponent 9 | 10 | /** 11 | * A [MvRxViewModelFactory] which makes it easy to create instances of a ViewModel 12 | * using its AssistedInject Factory. This class should be implemented by the companion object 13 | * of every ViewModel which uses AssistedInject. 14 | * 15 | * @param viewModelClass The [Class] of the ViewModel being requested for creation 16 | * 17 | * This class accesses the map of [AssistedViewModelFactory]s from [ApplicationComponent] via an [EntryPoint] 18 | * and uses it to retrieve the requested ViewModel's factory class. It then creates an instance of this ViewModel 19 | * using the retrieved factory and returns it. 20 | * 21 | * Example: 22 | * 23 | * class MyViewModel @AssistedInject constructor(...): BaseViewModel(...) { 24 | * 25 | * @AssistedInject.Factory 26 | * interface Factory : AssistedViewModelFactory { 27 | * ... 28 | * } 29 | * 30 | * companion object : DaggerMvRxViewModelFactory(MyViewModel::class.java) 31 | * 32 | * } 33 | */ 34 | abstract class DaggerMvRxViewModelFactory, S : MavericksState>( 35 | private val viewModelClass: Class> 36 | ) : MavericksViewModelFactory { 37 | 38 | override fun create(viewModelContext: ViewModelContext, state: S): VM? { 39 | return createViewModel(viewModelContext.activity, state) 40 | } 41 | 42 | private fun , S : MavericksState> createViewModel(fragmentActivity: FragmentActivity, state: S): VM { 43 | val viewModelFactoryMap = EntryPoints.get( 44 | fragmentActivity.applicationContext, DaggerMvrxViewModelFactoryEntryPoint::class.java 45 | ).viewModelFactories 46 | val viewModelFactory = viewModelFactoryMap[viewModelClass] 47 | @Suppress("UNCHECKED_CAST") 48 | val castedViewModelFactory = viewModelFactory as? AssistedViewModelFactory 49 | val viewModel = castedViewModelFactory?.create(state) 50 | return viewModel as VM 51 | } 52 | } 53 | 54 | @EntryPoint 55 | @InstallIn(ApplicationComponent::class) 56 | interface DaggerMvrxViewModelFactoryEntryPoint { 57 | val viewModelFactories: Map>, AssistedViewModelFactory<*, *>> 58 | } -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/di/AssistedViewModelFactory.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.di 2 | 3 | import com.airbnb.mvrx.MavericksState 4 | 5 | /* 6 | * Serves as a supertype for AssistedInject factories in ViewModels. 7 | * 8 | * We can use this interface as a marker in a Multibinding Dagger setup to populate a Map 9 | * of ViewModel classes with their AssistedInject factories. 10 | * 11 | * This setup is needed because AssistedInject factories are isolated from each other, so this 12 | * interface provides a common parent type to facilitate grouping these factories into a collection. 13 | * When we use it correctly with Dagger, a Map of ViewModels and their factories can be created for us 14 | * automatically. This Map can then be used to retrieve for a ViewModel's factory using its class. 15 | * 16 | * Here's an example for such a setup: 17 | * 18 | * First we define our ViewModel with an @AssistedInject annotated constructor, and a Factory interface 19 | * implementing AssistedViewModelFactory. 20 | * 21 | * class MyViewModel @AssistedInject constructor(...): BaseMvRxViewModel(...) { 22 | * @AssistedInject.Factory 23 | * interface Factory : AssistedViewModelFactory { 24 | * override fun create(state: MyState): MyViewModel 25 | * } 26 | * } 27 | * 28 | * Then we need to create a Dagger Module, which contains methods that @Binds @IntoMap all of our 29 | * AssistedViewModelFactories using a [ViewModelKey]. Notice that the input to these methods is 30 | * the exact type of our AssistedInject factory, but the return type is an AssistedViewModelFactory. 31 | * 32 | * @AssistedModule(includes = [AssistedInject_MyAppModule::class]) 33 | * @Module 34 | * interface MyAppModule { 35 | * @Binds 36 | * @IntoMap 37 | * @ViewModelKey(MyViewModel::class) 38 | * fun myViewModelFactory(factory: MyViewModel.Factory): AssistedViewModelFactory<*, *> 39 | * } 40 | * 41 | * This Module tells Dagger to include MyViewModel.Factory class in the Multibinding map using 42 | * MyViewModel::class as the key. Such a method should be added for **every ViewModel Factory** 43 | * so that they can be identified by Dagger and used for populating the Map. 44 | * 45 | * The generated map can then be injected wherever it is required. 46 | * 47 | * interface AppComponent { 48 | * fun viewModelFactories(): Map>, AssistedViewModelFactory<*, *>> 49 | * } 50 | * 51 | * class SomeClass @Inject constructor( 52 | * val viewModelFactories: Map>, AssistedViewModelFactory<*, *>> 53 | * ) 54 | */ 55 | interface AssistedViewModelFactory, S : MavericksState> { 56 | fun create(initialState: S): VM 57 | } -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/viewPaste/ViewPasteViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.viewPaste 2 | 3 | import androidx.hilt.Assisted 4 | import androidx.hilt.lifecycle.ViewModelInject 5 | import androidx.lifecycle.* 6 | import com.kriticalflare.bin_wrapper.BinWrapper 7 | import com.kriticalflare.bin_wrapper.remote.model.Paste 8 | import com.kriticalflare.nativbin.history.data.HistoryRepository 9 | import com.kriticalflare.nativbin.history.data.ViewedPaste 10 | import com.pddstudio.highlightjs.models.Language 11 | import kotlinx.coroutines.launch 12 | 13 | class ViewPasteViewModel @ViewModelInject constructor( 14 | private val historyRepository: HistoryRepository, 15 | @Assisted private val savedStateHandle: SavedStateHandle 16 | ) : ViewModel() { 17 | 18 | private val binWrapper = BinWrapper() 19 | private var _pastes = MutableLiveData() 20 | val pastes: LiveData = _pastes 21 | 22 | fun viewPaste(name: String) { 23 | viewModelScope.launch { 24 | try { 25 | _pastes.value = PasteResult.Loading 26 | val pastes = binWrapper.getPaste(name) 27 | if (pastes.isEmpty()) { 28 | _pastes.value = PasteResult.Error("Paste name is incorrect or it has expired") 29 | } else if (pastes.isNotEmpty()) { 30 | _pastes.value = PasteResult.Success(pastes[0]).also { 31 | historyRepository.insertViewedPaste( 32 | ViewedPaste( 33 | it.paste.name, 34 | it.paste.content, 35 | it.paste.language, 36 | it.paste.createdAt, 37 | it.paste.expiresAt 38 | ) 39 | ) 40 | } 41 | } else { 42 | _pastes.value = PasteResult.Error("Unknown Error") 43 | } 44 | } catch (t: Throwable) { 45 | _pastes.value = PasteResult.Error("${t.message}") 46 | } 47 | } 48 | } 49 | 50 | fun getContentLanguage(paste: Paste): Language? { 51 | when (paste.language) { 52 | "clike" -> { 53 | return Language.C 54 | } 55 | "python" -> { 56 | return Language.PYTHON 57 | } 58 | "json" -> { 59 | return Language.JSON 60 | } 61 | "Plain Text" -> { 62 | return Language.JSON 63 | } 64 | else -> { 65 | return Language.JSON 66 | } 67 | } 68 | } 69 | } 70 | 71 | sealed class PasteResult { 72 | object Loading : PasteResult() 73 | class Error(val error: String) : PasteResult() 74 | class Success(val paste: Paste) : PasteResult() 75 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_add_paste.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 20 | 21 | 26 | 27 | 37 | 47 | 48 | 57 | 58 | 68 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'kotlin-kapt' 5 | apply plugin: 'dagger.hilt.android.plugin' 6 | 7 | 8 | android { 9 | compileSdkVersion 30 10 | buildToolsVersion "30.0.2" 11 | 12 | defaultConfig { 13 | applicationId "com.kriticalflare.nativbin" 14 | minSdkVersion 23 15 | targetSdkVersion 30 16 | versionCode 1 17 | versionName "1.0" 18 | 19 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 20 | } 21 | 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 26 | } 27 | } 28 | 29 | compileOptions { 30 | sourceCompatibility JavaVersion.VERSION_1_8 31 | targetCompatibility JavaVersion.VERSION_1_8 32 | } 33 | kotlinOptions { 34 | jvmTarget = "1.8" 35 | } 36 | buildFeatures { 37 | viewBinding true 38 | } 39 | } 40 | 41 | kapt { 42 | correctErrorTypes = true 43 | } 44 | 45 | dependencies { 46 | 47 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 48 | def nav_version = "2.3.1" 49 | def room_version = "2.2.5" 50 | def epoxy_version = "4.1.0" 51 | 52 | implementation fileTree(dir: "libs", include: ["*.jar"]) 53 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 54 | implementation 'androidx.core:core-ktx:1.3.2' 55 | implementation 'androidx.fragment:fragment-ktx:1.2.5' 56 | implementation 'androidx.appcompat:appcompat:1.2.0' 57 | implementation 'androidx.constraintlayout:constraintlayout:2.0.2' 58 | 59 | implementation project(':bin-wrapper') 60 | 61 | implementation 'com.google.android.material:material:1.3.0-alpha03' 62 | 63 | implementation 'com.squareup.retrofit2:retrofit:2.9.0' 64 | implementation 'com.squareup.okhttp3:logging-interceptor:4.8.1' 65 | 66 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-beta01" 67 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0-beta01" 68 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-beta01" 69 | 70 | implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" 71 | implementation "androidx.navigation:navigation-ui-ktx:$nav_version" 72 | 73 | implementation "com.google.dagger:hilt-android:$hilt_version" 74 | kapt "com.google.dagger:hilt-android-compiler:$hilt_version" 75 | implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha02' 76 | kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha02' 77 | 78 | implementation "androidx.room:room-runtime:$room_version" 79 | kapt "androidx.room:room-compiler:$room_version" 80 | implementation "androidx.room:room-ktx:$room_version" 81 | 82 | implementation 'com.airbnb.android:mvrx:2.0.0-beta2' 83 | 84 | implementation "com.airbnb.android:epoxy:$epoxy_version" 85 | kapt "com.airbnb.android:epoxy-processor:$epoxy_version" 86 | 87 | implementation 'com.squareup.inject:assisted-inject-annotations-dagger2:0.6.0' 88 | kapt 'com.squareup.inject:assisted-inject-processor-dagger2:0.6.0' 89 | 90 | implementation 'com.github.ybq:Android-SpinKit:1.4.0' 91 | 92 | implementation 'com.pddstudio:highlightjs-android:1.5.0' 93 | implementation "com.github.markusressel:KodeEditor:3.0.2" 94 | 95 | implementation "com.github.skydoves:powermenu:2.1.5" 96 | 97 | testImplementation 'junit:junit:4.13.1' 98 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 99 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 100 | 101 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_view_paste.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 19 | 20 | 32 | 33 | 43 | 44 | 48 | 49 | 50 | 60 | 61 | 72 | 73 | 83 | 92 | 93 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 20 | 22 | 23 | 24 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | xmlns:android 33 | 34 | ^$ 35 | 36 | 37 | 38 |
39 |
40 | 41 | 42 | 43 | xmlns:.* 44 | 45 | ^$ 46 | 47 | 48 | BY_NAME 49 | 50 |
51 |
52 | 53 | 54 | 55 | .*:id 56 | 57 | http://schemas.android.com/apk/res/android 58 | 59 | 60 | 61 |
62 |
63 | 64 | 65 | 66 | .*:name 67 | 68 | http://schemas.android.com/apk/res/android 69 | 70 | 71 | 72 |
73 |
74 | 75 | 76 | 77 | name 78 | 79 | ^$ 80 | 81 | 82 | 83 |
84 |
85 | 86 | 87 | 88 | style 89 | 90 | ^$ 91 | 92 | 93 | 94 |
95 |
96 | 97 | 98 | 99 | .* 100 | 101 | ^$ 102 | 103 | 104 | BY_NAME 105 | 106 |
107 |
108 | 109 | 110 | 111 | .* 112 | 113 | http://schemas.android.com/apk/res/android 114 | 115 | 116 | ANDROID_ATTRIBUTE_ORDER 117 | 118 |
119 |
120 | 121 | 122 | 123 | .* 124 | 125 | .* 126 | 127 | 128 | BY_NAME 129 | 130 |
131 |
132 |
133 |
134 | 135 | 137 |
138 |
-------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/viewPaste/ViewPasteFragment.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.viewPaste 2 | 3 | import android.content.res.Configuration 4 | import android.graphics.Color 5 | import android.os.Build 6 | import android.os.Bundle 7 | import android.view.LayoutInflater 8 | import android.view.View 9 | import android.view.ViewGroup 10 | import androidx.appcompat.app.AppCompatDelegate 11 | import androidx.core.content.ContextCompat 12 | import androidx.fragment.app.Fragment 13 | import androidx.fragment.app.viewModels 14 | import androidx.lifecycle.Observer 15 | import androidx.navigation.fragment.FragmentNavigatorExtras 16 | import androidx.navigation.fragment.findNavController 17 | import com.google.android.material.transition.MaterialElevationScale 18 | import com.kriticalflare.nativbin.R 19 | import com.kriticalflare.nativbin.databinding.FragmentViewPasteBinding 20 | import com.pddstudio.highlightjs.models.Theme; 21 | import dagger.hilt.android.AndroidEntryPoint 22 | 23 | /** 24 | * A simple [Fragment] subclass. 25 | * Use the [ViewPasteFragment.newInstance] factory method to 26 | * create an instance of this fragment. 27 | */ 28 | @AndroidEntryPoint 29 | class ViewPasteFragment : Fragment() { 30 | 31 | private var _binding: FragmentViewPasteBinding? = null 32 | private val binding get() = _binding!! 33 | private val viewPasteViewModel:ViewPasteViewModel by viewModels() 34 | 35 | override fun onCreate(savedInstanceState: Bundle?) { 36 | super.onCreate(savedInstanceState) 37 | exitTransition = MaterialElevationScale(false).apply { 38 | duration = resources.getInteger(R.integer.motion_duration_large).toLong() 39 | } 40 | reenterTransition = MaterialElevationScale(true).apply { 41 | duration = resources.getInteger(R.integer.motion_duration_large).toLong() 42 | } 43 | } 44 | 45 | override fun onCreateView( 46 | inflater: LayoutInflater, container: ViewGroup?, 47 | savedInstanceState: Bundle? 48 | ): View? { 49 | // Inflate the layout for this fragment 50 | _binding = FragmentViewPasteBinding.inflate(inflater, container, false) 51 | return binding.root 52 | } 53 | 54 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 55 | super.onViewCreated(view, savedInstanceState) 56 | binding.codeView.apply { 57 | theme = if (isDarkMode()) Theme.DARK else Theme.GOOGLECODE 58 | } 59 | 60 | binding.mvrxFab.setOnClickListener { 61 | findNavController().navigate(R.id.action_viewPasteFragment_to_historyFragment) 62 | } 63 | arguments?.getString("name")?.let { 64 | binding.pasteText.setText(it) 65 | viewPasteViewModel.viewPaste(it) 66 | } 67 | viewPasteViewModel.pastes.observe(viewLifecycleOwner, Observer { pasteResult -> 68 | when (pasteResult) { 69 | is PasteResult.Loading -> { 70 | binding.codeView.visibility = View.GONE 71 | binding.viewPasteResultText.visibility = View.GONE 72 | binding.spinKit.visibility = View.VISIBLE 73 | } 74 | is PasteResult.Error -> { 75 | binding.viewPasteResultText.text = pasteResult.error 76 | binding.codeView.visibility = View.GONE 77 | binding.viewPasteResultText.visibility = View.VISIBLE 78 | binding.spinKit.visibility = View.GONE 79 | } 80 | is PasteResult.Success -> { 81 | binding.codeView.apply { 82 | setShowLineNumbers(true) 83 | setZoomSupportEnabled(true) 84 | highlightLanguage = viewPasteViewModel.getContentLanguage(pasteResult.paste) 85 | setSource(pasteResult.paste.content) 86 | visibility = View.VISIBLE 87 | setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.codeViewBackground)) 88 | } 89 | binding.viewPasteResultText.visibility = View.GONE 90 | binding.spinKit.visibility = View.GONE 91 | } 92 | else -> { 93 | // initial state 94 | binding.viewPasteResultText.text = "View paste" 95 | binding.viewPasteResultText.visibility = View.VISIBLE 96 | } 97 | } 98 | }) 99 | 100 | binding.pasteSearchBtn.setOnClickListener { 101 | viewPasteViewModel.viewPaste(binding.pasteText.text.toString()) 102 | } 103 | 104 | binding.addPasteFab.setOnClickListener { 105 | val extras = FragmentNavigatorExtras(binding.addPasteFab to "create_paste_transform") 106 | findNavController().navigate(R.id.action_viewPasteFragment_to_addPasteFragment, null, null, extras) 107 | } 108 | } 109 | 110 | private fun isDarkMode(): Boolean { 111 | return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { 112 | AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES 113 | } else { 114 | resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK === Configuration.UI_MODE_NIGHT_YES 115 | } 116 | } 117 | 118 | override fun onDestroyView() { 119 | super.onDestroyView() 120 | _binding = null 121 | } 122 | 123 | companion object { 124 | @JvmStatic 125 | fun newInstance() = 126 | ViewPasteFragment() 127 | } 128 | } -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/java/com/kriticalflare/nativbin/addPaste/AddPasteFragment.kt: -------------------------------------------------------------------------------- 1 | package com.kriticalflare.nativbin.addPaste 2 | 3 | import android.graphics.Color 4 | import android.graphics.Typeface 5 | import android.os.Bundle 6 | import android.view.Gravity 7 | import android.view.LayoutInflater 8 | import android.view.View 9 | import android.view.ViewGroup 10 | import android.widget.Toast 11 | import androidx.core.content.ContextCompat 12 | import androidx.fragment.app.Fragment 13 | import androidx.fragment.app.viewModels 14 | import androidx.interpolator.view.animation.FastOutLinearInInterpolator 15 | import androidx.interpolator.view.animation.FastOutSlowInInterpolator 16 | import androidx.lifecycle.LifecycleOwner 17 | import androidx.lifecycle.Observer 18 | import androidx.navigation.fragment.findNavController 19 | import com.google.android.material.snackbar.Snackbar 20 | import com.google.android.material.transition.MaterialArcMotion 21 | import com.google.android.material.transition.MaterialContainerTransform 22 | import com.kriticalflare.bin_wrapper.data.PasteResponse 23 | import com.kriticalflare.bin_wrapper.remote.model.UploadPaste 24 | import com.kriticalflare.nativbin.R 25 | import com.kriticalflare.nativbin.databinding.FragmentAddPasteBinding 26 | import com.kriticalflare.nativbin.utils.TimeInMinutes 27 | import com.kriticalflare.nativbin.utils.formatLanguageApi 28 | import com.skydoves.powermenu.PowerMenu 29 | import com.skydoves.powermenu.PowerMenuItem 30 | 31 | 32 | class AddPasteFragment : Fragment() { 33 | 34 | private var _binding: FragmentAddPasteBinding? = null 35 | private val binding get() = _binding!! 36 | 37 | override fun onCreate(savedInstanceState: Bundle?) { 38 | super.onCreate(savedInstanceState) 39 | sharedElementEnterTransition = MaterialContainerTransform().apply { 40 | scrimColor = Color.TRANSPARENT 41 | duration = resources.getInteger(R.integer.motion_duration_large).toLong() 42 | setPathMotion(MaterialArcMotion()) 43 | interpolator = FastOutLinearInInterpolator() 44 | fadeMode = MaterialContainerTransform.FADE_MODE_OUT 45 | } 46 | } 47 | 48 | override fun onCreateView( 49 | inflater: LayoutInflater, container: ViewGroup?, 50 | savedInstanceState: Bundle? 51 | ): View? { 52 | // Inflate the layout for this fragment 53 | _binding = FragmentAddPasteBinding.inflate(inflater, container, false) 54 | return binding.root 55 | } 56 | 57 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 58 | super.onViewCreated(view, savedInstanceState) 59 | 60 | val viewModel by viewModels() 61 | 62 | val languageMenuList = listOf( 63 | PowerMenuItem("Plain Text", true), 64 | PowerMenuItem("Python"), 65 | PowerMenuItem("Json"), 66 | PowerMenuItem("C Like") 67 | ) 68 | 69 | val timeMenuList = listOf( 70 | PowerMenuItem("One day", true), 71 | PowerMenuItem("One week"), 72 | PowerMenuItem("One month") 73 | ) 74 | 75 | val languageMenu = setupPowerMenu(languageMenuList,viewLifecycleOwner) 76 | val timeMenu = setupPowerMenu(timeMenuList, viewLifecycleOwner) 77 | 78 | 79 | binding.languageImg.setOnClickListener { 80 | languageMenu.showAsDropDown(binding.languageImg) 81 | } 82 | 83 | binding.timeImg.setOnClickListener { 84 | timeMenu.showAsDropDown(binding.timeImg) 85 | } 86 | 87 | binding.uploadFab.setOnClickListener { 88 | if(isValidPasteName(binding)){ 89 | viewModel.uploadPaste(UploadPaste( 90 | name = binding.pasteUrlEdit.text.toString(), 91 | content = binding.pasteCodeLayout.text, 92 | language = languageMenuList[languageMenu.selectedPosition].title.toString().formatLanguageApi(), 93 | expiresInMinutes = TimeInMinutes(timeMenuList[timeMenu.selectedPosition].title.toString()) 94 | )) 95 | } 96 | } 97 | 98 | viewModel.uploadStatus.observe(viewLifecycleOwner, Observer { 99 | when(val event = it.getContentIfNotHandled()){ 100 | is PasteResponse.Success -> { 101 | findNavController().popBackStack() 102 | } 103 | is PasteResponse.Failure -> { 104 | Snackbar.make(binding.root, event.message, Snackbar.LENGTH_LONG).show() 105 | } 106 | } 107 | }) 108 | } 109 | 110 | private fun setupPowerMenu(list: List, lifecycleOwner: LifecycleOwner): PowerMenu { 111 | val powerMenu = PowerMenu.Builder(requireContext()) 112 | .addItemList(list) 113 | .setMenuRadius(10f) 114 | .setMenuShadow(10f) 115 | .setLifecycleOwner(lifecycleOwner) 116 | .setTextColor(ContextCompat.getColor(requireContext(), R.color.popupText)) 117 | .setTextGravity(Gravity.CENTER) 118 | .setTextTypeface(Typeface.create("sans-serif-medium", Typeface.BOLD)) 119 | .setSelectedTextColor(Color.WHITE) 120 | .setMenuColor(ContextCompat.getColor(requireContext(), R.color.popupBackground)) 121 | .setSelectedMenuColor(ContextCompat.getColor(requireContext(), R.color.purple_500)) 122 | .setSelected(0) 123 | .build() 124 | 125 | powerMenu.setOnMenuItemClickListener { position, item -> 126 | powerMenu.selectedPosition = position 127 | Toast.makeText(requireContext(), item.title, Toast.LENGTH_SHORT).show() 128 | } 129 | return powerMenu 130 | } 131 | 132 | private fun isValidPasteName(binding: FragmentAddPasteBinding): Boolean { 133 | return if(binding.pasteUrlEdit.text.toString().isEmpty()){ 134 | binding.editLayout.isErrorEnabled = true 135 | binding.editLayout.error = "Paste name cannot be empty" 136 | false 137 | } else { 138 | if(binding.editLayout.isErrorEnabled){ 139 | binding.editLayout.error = null 140 | } 141 | true 142 | } 143 | } 144 | 145 | 146 | override fun onDestroyView() { 147 | super.onDestroyView() 148 | _binding = null 149 | } 150 | 151 | companion object { 152 | 153 | @JvmStatic 154 | fun newInstance(param1: String, param2: String) = 155 | AddPasteFragment() 156 | } 157 | } --------------------------------------------------------------------------------