Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add empty view UI for no Files/Folders #6

Merged
merged 3 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ repositories {
gradlePluginPortal()
}

configurations.all {
resolutionStrategy.eachDependency {
when (requested.name) {
"javapoet" -> useVersion("1.13.0")
}
}
}

dependencies {
gradleApi()
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20")
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/ConfigData.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object ConfigData {
const val compileSdkVersion = 33
const val minSdkVersion = 21
const val minSdkVersion = 23
const val targetSdkVersion = 29
}
39 changes: 39 additions & 0 deletions storage-sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,30 +1,69 @@
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties

plugins {
`android-application`
id("kotlin-kapt")
id("com.google.dagger.hilt.android") version "2.44" apply true
}

@Suppress("UnstableApiUsage")
android {
namespace = "com.omh.android.storage.sample"

defaultConfig {
buildConfigField(
type = "String",
name = "CLIENT_ID",
value = gradleLocalProperties(rootDir)["clientId"].toString()
)
}

buildTypes {
release {
isMinifyEnabled = false
}
}

flavorDimensions += "google_services"
productFlavors {
create("ngms") {
dimension = "google_services"
}
}

kotlinOptions {
jvmTarget = "1.8"
}

viewBinding {
enable = true
}

kapt {
correctErrorTypes = true
}
}

val ngmsImplementation by configurations

dependencies {
implementation(project(":storage-api"))

ngmsImplementation("com.omh.android:auth-non-gms:1.0-SNAPSHOT")
ngmsImplementation(project(":storage-api-drive-nongms"))

implementation(Libs.coreKtx)
implementation(Libs.lifecycleKtx)
implementation(Libs.androidAppCompat)
implementation(Libs.material)
implementation(Libs.coroutinesAndroid)
implementation("com.github.bumptech.glide:glide:4.14.2")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
annotationProcessor("com.github.bumptech.glide:compiler:4.14.2")

// Hilt
implementation("com.google.dagger:hilt-android:2.44")
kapt("com.google.dagger:hilt-compiler:2.44")

testImplementation(Libs.junit)
}
25 changes: 24 additions & 1 deletion storage-sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,33 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name=".DemoApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Omhstorage" />
android:theme="@style/Theme.OMHStorage">

<activity
android:name=".login.ActivityLogin"
android:exported="true"
android:resizeableActivity="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".splash.ActivitySplash"
android:exported="false"
android:label="Splash" />

<activity
android:name=".drive.ActivityFilesAndFolders"
android:exported="false"
android:label="Storage" />

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.omh.android.storage.sample

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class DemoApp : Application()
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.omh.android.storage.sample.di

import android.content.Context
import com.omh.android.auth.api.OmhAuthClient
import com.omh.android.auth.api.OmhAuthProvider
import com.omh.android.storage.sample.BuildConfig
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
class SingletonModule {
@Provides
fun providesOmhAuthClient(@ApplicationContext context: Context): OmhAuthClient {
return OmhAuthProvider.provideAuthClient(
scopes = listOf("openid", "email", "profile"),
clientId = BuildConfig.CLIENT_ID,
context = context
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.omh.android.storage.sample.drive

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.omh.android.storage.sample.databinding.ActivityFilesFoldersBinding

class ActivityFilesAndFolders : AppCompatActivity() {

private val binding: ActivityFilesFoldersBinding by lazy {
ActivityFilesFoldersBinding.inflate(layoutInflater)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
binding.recvEmptyView.root.visibility = View.VISIBLE
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.omh.android.storage.sample.login

import android.content.Intent
import android.os.Bundle
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.omh.android.auth.api.OmhAuthClient
import com.omh.android.storage.sample.databinding.ActivityLoginBinding
import com.omh.android.storage.sample.splash.ActivitySplash
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class ActivityLogin : AppCompatActivity() {

private val loginLauncher: ActivityResultLauncher<Intent> = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result ->
try {
omhAuthClient.getAccountFromIntent(result.data)
navigateToSplash()
} catch (exception: Exception) {
AlertDialog.Builder(this)
.setTitle("An error has occurred.")
.setMessage(exception.message)
.setPositiveButton(android.R.string.ok) { dialog, _ ->
dialog.dismiss()
}
.create()
.show()
}
}

private val binding: ActivityLoginBinding by lazy {
ActivityLoginBinding.inflate(layoutInflater)
}

@Inject
lateinit var omhAuthClient: OmhAuthClient

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
binding.btnLogin.setOnClickListener { startLogin() }

if (omhAuthClient.getUser() != null) {
navigateToSplash()
}
}

private fun startLogin() {
loginLauncher.launch(omhAuthClient.getLoginIntent())
}

private fun navigateToSplash() {
val intent = Intent(this, ActivitySplash::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(intent)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.omh.android.storage.sample.splash

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.omh.android.auth.api.OmhAuthClient
import com.omh.android.storage.sample.databinding.ActivitySplashBinding
import com.omh.android.storage.sample.drive.ActivityFilesAndFolders
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject

@AndroidEntryPoint
class ActivitySplash : AppCompatActivity() {

@Inject
lateinit var omhAuthClient: OmhAuthClient

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(ActivitySplashBinding.inflate(layoutInflater).root)
checkUserThenNavigate()
}

private fun checkUserThenNavigate() = lifecycleScope.launch(Dispatchers.IO) {
if (omhAuthClient.getUser() != null) {
navigateToFilesAndFolders()
}
}

private fun navigateToFilesAndFolders() {
val intent = Intent(this, ActivityFilesAndFolders::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(intent)
}

}
6 changes: 6 additions & 0 deletions storage-sample/src/main/res/drawable/outline_folder.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20,6h-8l-2,-2H7.17l4,4H20v9.17l1.76,1.76C21.91,18.65 22,18.34 22,18V8C22,6.9 21.1,6 20,6z"/>
<path android:fillColor="@android:color/white" android:pathData="M2.1,2.1L0.69,3.51l1.56,1.56C2.1,5.35 2.01,5.66 2.01,6L2,18c0,1.1 0.9,2 2,2h13.17l3.31,3.31l1.41,-1.41L2.1,2.1zM4,18V6.83L15.17,18H4z"/>
</vector>
11 changes: 11 additions & 0 deletions storage-sample/src/main/res/layout/activity_files_folders.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include
android:id="@+id/recv_empty_view"
layout="@layout/empty_view"
android:visibility="gone" />

</FrameLayout>
19 changes: 19 additions & 0 deletions storage-sample/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".login.ActivityLogin">

<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_login"
android:text="@string/login"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
17 changes: 17 additions & 0 deletions storage-sample/src/main/res/layout/activity_splash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/flaySplash"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".splash.ActivitySplash">

<TextView
android:id="@+id/tvSplashLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/loading"
android:textSize="32sp" />

</FrameLayout>
24 changes: 24 additions & 0 deletions storage-sample/src/main/res/layout/empty_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables">

<ImageView
android:id="@+id/ivEmptyFolder"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/outline_folder"
tools:ignore="ContentDescription" />

<TextView
android:id="@+id/tvEmptyFolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/empty_folder" />

</LinearLayout>
2 changes: 1 addition & 1 deletion storage-sample/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Omhstorage" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.OMHStorage" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down
6 changes: 5 additions & 1 deletion storage-sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<resources>
<string name="app_name">omh storage demo</string>
<string name="app_name">OMH Storage demo</string>

<string name="login">Login</string>
<string name="loading">Loading…</string>
<string name="empty_folder">This folder is empty</string>
</resources>
2 changes: 1 addition & 1 deletion storage-sample/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Omhstorage" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.OMHStorage" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down