commit 3c8a8522d8d0a1f6aaf28fae0ef590fdf0719d8d Author: dadada Date: Sat Nov 7 20:39:23 2020 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01684f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties +app/release diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..3c7772a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,139 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..b617266 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,23 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..a5f05cd --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d5d35ec --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ba253e3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,192 @@ + + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + Copyright 2013-2018 Docker, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..fe03a25 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,60 @@ +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'kotlin-kapt' +} + +android { + compileSdkVersion 30 + + defaultConfig { + applicationId "li.dadada.uuidgen" + minSdkVersion 22 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled true + shrinkResources true + debuggable false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + debug { + applicationIdSuffix ".debug" + debuggable true + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + + buildFeatures { + dataBinding = true + } +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.2.1' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1' + implementation 'androidx.navigation:navigation-ui-ktx:2.3.1' + implementation "androidx.room:room-runtime:$room_version" + kapt "androidx.room:room-compiler:$room_version" + implementation "androidx.room:room-ktx:$room_version" + testImplementation "androidx.room:room-testing:$room_version" + testImplementation 'junit:junit:4.13.1' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/li/dadada/uuidgen/ExampleInstrumentedTest.kt b/app/src/androidTest/java/li/dadada/uuidgen/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..174f890 --- /dev/null +++ b/app/src/androidTest/java/li/dadada/uuidgen/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package li.dadada.uuidgen + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("li.dadada.uuidgen", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..4e5913c --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-playstore.png b/app/src/main/ic_launcher-playstore.png new file mode 100644 index 0000000..7169886 Binary files /dev/null and b/app/src/main/ic_launcher-playstore.png differ diff --git a/app/src/main/java/li/dadada/uuidgen/UuidGen.kt b/app/src/main/java/li/dadada/uuidgen/UuidGen.kt new file mode 100644 index 0000000..e855cc0 --- /dev/null +++ b/app/src/main/java/li/dadada/uuidgen/UuidGen.kt @@ -0,0 +1,19 @@ +package li.dadada.uuidgen + +import android.app.Application +import androidx.room.Room +import li.dadada.uuidgen.model.AppDatabase +import li.dadada.uuidgen.model.UuidDao + +class UuidGen : Application() { + internal val uuidDao : UuidDao by lazy { + db.uuidDao() + } + + private val db: AppDatabase by lazy { + Room.databaseBuilder( + applicationContext, + AppDatabase::class.java, "uuids" + ).build() + } +} \ No newline at end of file diff --git a/app/src/main/java/li/dadada/uuidgen/model/AppDatabase.kt b/app/src/main/java/li/dadada/uuidgen/model/AppDatabase.kt new file mode 100644 index 0000000..719ec2d --- /dev/null +++ b/app/src/main/java/li/dadada/uuidgen/model/AppDatabase.kt @@ -0,0 +1,9 @@ +package li.dadada.uuidgen.model + +import androidx.room.Database +import androidx.room.RoomDatabase + +@Database(entities = [Uuid::class], version = 1) +abstract class AppDatabase : RoomDatabase() { + abstract fun uuidDao(): UuidDao +} diff --git a/app/src/main/java/li/dadada/uuidgen/model/Uuid.kt b/app/src/main/java/li/dadada/uuidgen/model/Uuid.kt new file mode 100644 index 0000000..397531f --- /dev/null +++ b/app/src/main/java/li/dadada/uuidgen/model/Uuid.kt @@ -0,0 +1,32 @@ +package li.dadada.uuidgen.model + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import java.util.* + +@Entity +data class Uuid( + @PrimaryKey val uuid: String = UUID.randomUUID().toString(), + @ColumnInfo(name = "created") val created: Long = Date().time +) { + override fun toString(): String { + return uuid + } + + override fun equals(other: Any?): Boolean { + return if (other !is Uuid) { + false + } else { + uuid == other.uuid + } + } + + override fun hashCode(): Int { + var result = uuid.hashCode() + result = 31 * result + created.hashCode() + return result + } +} + + diff --git a/app/src/main/java/li/dadada/uuidgen/model/UuidDao.kt b/app/src/main/java/li/dadada/uuidgen/model/UuidDao.kt new file mode 100644 index 0000000..0304333 --- /dev/null +++ b/app/src/main/java/li/dadada/uuidgen/model/UuidDao.kt @@ -0,0 +1,19 @@ +package li.dadada.uuidgen.model + +import androidx.lifecycle.LiveData +import androidx.room.* + +@Dao +interface UuidDao { + @Query("SELECT * FROM `uuid` ORDER BY `created` ASC") + fun getAll(): LiveData> + + @Query("SELECT * FROM `uuid` WHERE `uuid` IS :uuid") + fun get(uuid: String) : List + + @Insert(onConflict = OnConflictStrategy.ABORT) + fun insertAll(vararg uuid: Uuid) + + @Delete + fun delete(user: Uuid) +} diff --git a/app/src/main/java/li/dadada/uuidgen/ui/MainActivity.kt b/app/src/main/java/li/dadada/uuidgen/ui/MainActivity.kt new file mode 100644 index 0000000..ad0154c --- /dev/null +++ b/app/src/main/java/li/dadada/uuidgen/ui/MainActivity.kt @@ -0,0 +1,37 @@ +package li.dadada.uuidgen.ui + +import android.os.Bundle +import android.view.Menu +import android.view.MenuItem +import androidx.appcompat.app.AppCompatActivity +import androidx.navigation.findNavController +import kotlinx.coroutines.* +import li.dadada.uuidgen.* + + +class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContentView(R.layout.activity_main) + setSupportActionBar(findViewById(R.id.toolbar)) + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + // Inflate the menu; this adds items to the action bar if it is present. + menuInflater.inflate(R.menu.menu_main, menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return when (item.itemId) { + R.id.action_history -> { + findNavController(R.id.nav_host_fragment) + .navigate(R.id.action_uuid_gen_fragment_to_uuid_list_fragment) + true + } + else -> super.onOptionsItemSelected(item) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/li/dadada/uuidgen/ui/UuidGenFragment.kt b/app/src/main/java/li/dadada/uuidgen/ui/UuidGenFragment.kt new file mode 100644 index 0000000..948fae4 --- /dev/null +++ b/app/src/main/java/li/dadada/uuidgen/ui/UuidGenFragment.kt @@ -0,0 +1,52 @@ +package li.dadada.uuidgen.ui + +import android.content.ClipboardManager +import android.content.Context +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.fragment.app.Fragment +import androidx.lifecycle.ViewModelProvider +import com.google.android.material.snackbar.Snackbar +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.MainScope +import kotlinx.coroutines.launch +import li.dadada.uuidgen.R +import li.dadada.uuidgen.databinding.UuidGenFragmentBinding +import li.dadada.uuidgen.viewmodel.ClipBoardUtil +import li.dadada.uuidgen.viewmodel.UuidViewModel + + +class UuidGenFragment : Fragment(), CoroutineScope by MainScope() { + + private val viewModel: UuidViewModel by lazy { + ViewModelProvider(this).get(UuidViewModel::class.java) + } + + private lateinit var clipboardManager: ClipboardManager + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + val binding: UuidGenFragmentBinding = + DataBindingUtil.inflate(inflater, R.layout.uuid_gen_fragment, container, false) + clipboardManager = inflater.context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + binding.buttonGen.setOnClickListener { view -> + launch { genUuid(view) } + } + return binding.root + } + + private suspend fun genUuid(view: View) { + val uuid = viewModel.genUuid() + if (uuid != null) { + ClipBoardUtil.copyUuid(uuid, view, clipboardManager) + } else { + Snackbar.make(view, R.string.warn_duplicate_uuid, Snackbar.LENGTH_SHORT) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/li/dadada/uuidgen/ui/UuidListFragment.kt b/app/src/main/java/li/dadada/uuidgen/ui/UuidListFragment.kt new file mode 100644 index 0000000..c23e45d --- /dev/null +++ b/app/src/main/java/li/dadada/uuidgen/ui/UuidListFragment.kt @@ -0,0 +1,58 @@ +package li.dadada.uuidgen.ui + +import android.content.ClipboardManager +import android.content.Context.CLIPBOARD_SERVICE +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.lifecycle.Observer +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import li.dadada.uuidgen.R +import li.dadada.uuidgen.model.Uuid +import li.dadada.uuidgen.viewmodel.UuidAdapter +import li.dadada.uuidgen.viewmodel.UuidViewModel +import li.dadada.uuidgen.databinding.UuidListFragmentBinding +import li.dadada.uuidgen.viewmodel.ClipBoardUtil +import li.dadada.uuidgen.viewmodel.OnUuidClickListener + + +/** + * A simple [Fragment] subclass as the default destination in the navigation. + */ +class UuidListFragment : Fragment() { + private val uuidAdapter = UuidAdapter(object : OnUuidClickListener { + override fun onUuidClicked(view: View, uuid: Uuid): Boolean { + ClipBoardUtil.copyUuid( + uuid, + view, + activity?.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager) + return true + } + }) + + private lateinit var binding : UuidListFragmentBinding + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = DataBindingUtil.inflate(inflater, R.layout.uuid_list_fragment, container, false) + binding.listUuids.apply { + adapter = uuidAdapter + layoutManager = LinearLayoutManager(this@UuidListFragment.context) + } + + return binding.root; + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val viewModel = ViewModelProvider(this).get(UuidViewModel::class.java) + viewModel.uuidList.observe(viewLifecycleOwner, + Observer> { list -> uuidAdapter.submitList(list) }) + } +} \ No newline at end of file diff --git a/app/src/main/java/li/dadada/uuidgen/viewmodel/ClipBoardUtil.kt b/app/src/main/java/li/dadada/uuidgen/viewmodel/ClipBoardUtil.kt new file mode 100644 index 0000000..adb0bef --- /dev/null +++ b/app/src/main/java/li/dadada/uuidgen/viewmodel/ClipBoardUtil.kt @@ -0,0 +1,16 @@ +package li.dadada.uuidgen.viewmodel + +import android.content.ClipData +import android.content.ClipboardManager +import android.view.View +import com.google.android.material.snackbar.BaseTransientBottomBar +import com.google.android.material.snackbar.Snackbar +import li.dadada.uuidgen.model.Uuid + +object ClipBoardUtil { + fun copyUuid(uuid: Uuid, view: View, clipboardManager: ClipboardManager) { + clipboardManager.setPrimaryClip(ClipData.newPlainText("uuid", uuid.uuid)) + Snackbar.make(view, "Copied $uuid to clipboard", BaseTransientBottomBar.LENGTH_SHORT) + .show() + } +} \ No newline at end of file diff --git a/app/src/main/java/li/dadada/uuidgen/viewmodel/OnUuidClickListener.kt b/app/src/main/java/li/dadada/uuidgen/viewmodel/OnUuidClickListener.kt new file mode 100644 index 0000000..e174164 --- /dev/null +++ b/app/src/main/java/li/dadada/uuidgen/viewmodel/OnUuidClickListener.kt @@ -0,0 +1,8 @@ +package li.dadada.uuidgen.viewmodel + +import android.view.View +import li.dadada.uuidgen.model.Uuid + +interface OnUuidClickListener { + fun onUuidClicked(view: View, uuid: Uuid) : Boolean +} \ No newline at end of file diff --git a/app/src/main/java/li/dadada/uuidgen/viewmodel/UuidAdapter.kt b/app/src/main/java/li/dadada/uuidgen/viewmodel/UuidAdapter.kt new file mode 100644 index 0000000..0232a7f --- /dev/null +++ b/app/src/main/java/li/dadada/uuidgen/viewmodel/UuidAdapter.kt @@ -0,0 +1,56 @@ +package li.dadada.uuidgen.viewmodel + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.ListAdapter +import androidx.recyclerview.widget.RecyclerView +import li.dadada.uuidgen.R +import li.dadada.uuidgen.databinding.UuidItemBinding +import li.dadada.uuidgen.model.Uuid + + +class UuidAdapter(private val controller: OnUuidClickListener) : ListAdapter(UuidDiffCallback()) { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UuidViewHolder { + return from(parent, controller) + } + + override fun onBindViewHolder(holder: UuidViewHolder, position: Int) { + val item = getItem(position) + holder.bind(item) + } + + class UuidViewHolder( + private val binding: UuidItemBinding, + private val listener: OnUuidClickListener + ) : RecyclerView.ViewHolder(binding.root) { + fun bind(item: Uuid) { + binding.uuid = item + binding.listener = listener + binding.executePendingBindings() + } + } + + companion object { + fun from(parent: ViewGroup, listener: OnUuidClickListener) : UuidViewHolder { + val binding : UuidItemBinding = DataBindingUtil.inflate( + LayoutInflater.from(parent.context), + R.layout.uuid_item, + parent, false + ) + return UuidViewHolder(binding, listener) + } + } +} + +class UuidDiffCallback : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: Uuid, newItem: Uuid): Boolean { + return oldItem == newItem + } + + override fun areContentsTheSame(oldItem: Uuid, newItem: Uuid): Boolean { + return oldItem == newItem + } +} \ No newline at end of file diff --git a/app/src/main/java/li/dadada/uuidgen/viewmodel/UuidViewModel.kt b/app/src/main/java/li/dadada/uuidgen/viewmodel/UuidViewModel.kt new file mode 100644 index 0000000..a9b71f4 --- /dev/null +++ b/app/src/main/java/li/dadada/uuidgen/viewmodel/UuidViewModel.kt @@ -0,0 +1,45 @@ +package li.dadada.uuidgen.viewmodel + +import android.app.Application +import android.content.ClipData +import android.content.ClipboardManager +import android.view.View +import androidx.lifecycle.AndroidViewModel +import androidx.lifecycle.SavedStateHandle +import com.google.android.material.snackbar.BaseTransientBottomBar +import com.google.android.material.snackbar.Snackbar +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import li.dadada.uuidgen.UuidGen +import li.dadada.uuidgen.model.Uuid +import li.dadada.uuidgen.model.UuidDao + + +internal class UuidViewModel(application: Application, + savedStateHandle: SavedStateHandle +) : AndroidViewModel(application) { + + private val uuidDao : UuidDao by lazy { + (application as UuidGen).uuidDao + } + + val uuidList = uuidDao.getAll() + + suspend fun genUuid() : Uuid? { + return genUuid(uuidDao) + } + + companion object { + private suspend fun genUuid(uuidDao: UuidDao) : Uuid? = withContext(Dispatchers.IO) { + val uuid = Uuid() + with(uuidDao) { + if (get(uuid.uuid).isEmpty()) { + insertAll(uuid) + uuid + } else { + null + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1d1edde --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,31 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/ic_baseline_history_24.xml b/app/src/main/res/drawable/ic_baseline_history_24.xml new file mode 100644 index 0000000..9bc1fc3 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_history_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..f815f44 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,31 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/uuid_selector.xml b/app/src/main/res/drawable/uuid_selector.xml new file mode 100644 index 0000000..feb9be5 --- /dev/null +++ b/app/src/main/res/drawable/uuid_selector.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/app/src/main/res/drawable/uuidgen.xml b/app/src/main/res/drawable/uuidgen.xml new file mode 100644 index 0000000..f3ae47c --- /dev/null +++ b/app/src/main/res/drawable/uuidgen.xml @@ -0,0 +1,16 @@ + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..342aa5c --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml new file mode 100644 index 0000000..5474c02 --- /dev/null +++ b/app/src/main/res/layout/content_main.xml @@ -0,0 +1,19 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/uuid_gen_fragment.xml b/app/src/main/res/layout/uuid_gen_fragment.xml new file mode 100644 index 0000000..79a2704 --- /dev/null +++ b/app/src/main/res/layout/uuid_gen_fragment.xml @@ -0,0 +1,25 @@ + + + + + + + + + +