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 Splashscreen and dialog logout #11

Merged
merged 1 commit into from
Apr 23, 2022
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
2 changes: 2 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@
android:supportsRtl="true"
android:theme="@style/Theme.NFTMarketplace">
<activity
android:name="com.djevannn.nftmarketplace.ui.main.user_nft.NFTUserActivity"
android:name=".ui.splash_screen.SplashScreenActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.main.user_nft.NFTUserActivity"
android:exported="false" />
<activity
android:name=".ui.main.listings.ListingActivity"
Expand Down Expand Up @@ -50,20 +59,12 @@
<activity
android:name=".ui.main.detail.DetailActivity"
android:exported="false"
android:label="@string/title_activity_detail" /> <!-- > -->
<!-- <meta-data -->
<!-- android:name="android.support.PARENT_ACTIVITY" -->
<!-- android:value=".MainActivity" /> -->
<!-- </activity> -->
android:label="@string/title_activity_detail" />
<activity
android:name=".MainActivity"
android:exported="true"
android:exported="false"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.djevannn.nftmarketplace.ui.auth.login.LoginViewModel
import com.djevannn.nftmarketplace.ui.user.profile.ProfileViewModel
import com.djevannn.nftmarketplace.ui.auth.register.RegisterViewModel
import com.djevannn.nftmarketplace.ui.main.user_nft.NFTUserViewModel
import com.djevannn.nftmarketplace.ui.splash_screen.SplashScreenViewModel

class ViewModelFactory(private val pref: UserPreference) :
ViewModelProvider.NewInstanceFactory() {
Expand Down Expand Up @@ -53,6 +54,9 @@ class ViewModelFactory(private val pref: UserPreference) :
modelClass.isAssignableFrom(AddViewModel::class.java) -> {
AddViewModel(pref) as T
}
modelClass.isAssignableFrom(SplashScreenViewModel::class.java) -> {
SplashScreenViewModel(pref) as T
}
else -> throw IllegalArgumentException("Unknown ViewModel class: " + modelClass.name)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.djevannn.nftmarketplace.ui.splash_screen

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AppCompatDelegate
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import androidx.lifecycle.ViewModelProvider
import com.djevannn.nftmarketplace.MainActivity
import com.djevannn.nftmarketplace.ViewModelFactory
import com.djevannn.nftmarketplace.databinding.ActivitySplashScreenBinding
import com.djevannn.nftmarketplace.helper.UserPreference

private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(
name = "settings"
)

class SplashScreenActivity : AppCompatActivity() {
private lateinit var binding : ActivitySplashScreenBinding
private lateinit var viewModel: SplashScreenViewModel
private val times = 1000L
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySplashScreenBinding.inflate(layoutInflater)
setContentView(binding.root)

setupView()
setupViewModel()
setupAction()
}

private fun setupView() {
supportActionBar?.hide()
}

private fun setupViewModel() {
viewModel = ViewModelProvider(
this,
ViewModelFactory(UserPreference.getInstance(dataStore))
)[SplashScreenViewModel::class.java]

viewModel.getThemeSetting().observe(this) {
when (it) {
0 -> {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
)
}
1 -> {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_NO
)
}
2 -> {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_YES
)
}
}
}
}

private fun setupAction() {
Handler(Looper.getMainLooper()).postDelayed({
val intent = Intent(this@SplashScreenActivity, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
finish()
}, times)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.djevannn.nftmarketplace.ui.splash_screen

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import com.djevannn.nftmarketplace.helper.UserPreference

class SplashScreenViewModel(private val pref: UserPreference): ViewModel() {

fun getThemeSetting(): LiveData<Int> {
return pref.getThemeSetting().asLiveData()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CollectionActivity : AppCompatActivity() {
setContentView(binding.root)

supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.title = getString(R.string.collections_page)
supportActionBar?.title = getString(R.string.collection_page)

viewModel = ViewModelProvider(
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.djevannn.nftmarketplace.MainActivity
import com.djevannn.nftmarketplace.R
import com.djevannn.nftmarketplace.ViewModelFactory
import com.djevannn.nftmarketplace.data.User
Expand Down Expand Up @@ -144,8 +145,8 @@ class ProfileFragment : Fragment() {
startActivity(intent)
}
binding.btnLogout.setOnClickListener {
viewModel.logout()
activity?.finish()
showLogoutDialog()

}
binding.btnLanguage.setOnClickListener {
startActivity(Intent(Settings.ACTION_LOCALE_SETTINGS))
Expand Down Expand Up @@ -193,4 +194,27 @@ class ProfileFragment : Fragment() {

builder.show()
}

private fun showLogoutDialog() {
val builder =
AlertDialog.Builder(requireContext(), 0).create()
val view =
layoutInflater.inflate(R.layout.dialog_logout, null)
val btnConfirm = view.findViewById<Button>(R.id.btn_confirm)
val btnCancel = view.findViewById<Button>(R.id.btn_cancel)

builder.setView(view)

btnConfirm.setOnClickListener {
viewModel.logout()
val i = Intent(activity, MainActivity::class.java)
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(i)
}
btnCancel.setOnClickListener {
builder.dismiss()
}

builder.show()
}
}
Binary file added app/src/main/res/drawable/logo_enft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions app/src/main/res/layout/activity_splash_screen.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=".ui.splash_screen.SplashScreenActivity">

<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:src="@drawable/logo_enft"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="ContentDescription" />

</androidx.constraintlayout.widget.ConstraintLayout>
57 changes: 57 additions & 0 deletions app/src/main/res/layout/dialog_logout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/txtColorSecondary">

<TextView
android:id="@+id/textView2"
style="@style/txtColorBlue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="@string/logout"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_logout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp"
android:textSize="16sp"
android:text="Do you want to logout?"
app:layout_constraintTop_toBottomOf="@id/textView2"
app:layout_constraintStart_toStartOf="parent"/>

<Button
android:id="@+id/btn_confirm"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="@string/confirm"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_logout" />

<Button
android:id="@+id/btn_cancel"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="@string/cancel"
android:textColor="@color/grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btn_confirm"
app:layout_constraintTop_toTopOf="@+id/btn_confirm" />

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">NFT Marketplace</string>
<string name="app_name">E NFT</string>
<string name="title_home">Explore NFTs</string>
<string name="title_add">Create NFT</string>
<string name="title_profile">My Profile</string>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.20' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false

// Firebase
id 'com.google.gms.google-services' version '4.3.8'
Expand Down