[GSoC] Welcome Dialog (#4546)

* Welcome Dialog

* Condition Fix

* Orientation, back button Fix
This commit is contained in:
Aditya-Srivastav 2021-08-14 06:33:26 +05:30 committed by GitHub
parent 79447cfaf3
commit 25156d0e94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 163 additions and 2 deletions

View file

@ -110,7 +110,7 @@ class ImageAdapter(
} }
} else { } else {
if(holder.isItemUploaded()){ if(holder.isItemUploaded()){
Toast.makeText(context, "Already Uploaded image", Toast.LENGTH_SHORT).show() Toast.makeText(context, R.string.custom_selector_already_uploaded_image_text, Toast.LENGTH_SHORT).show()
} else { } else {
selectedImages.add(images[position]) selectedImages.add(images[position])
notifyItemChanged(position, ImageSelectedOrUpdated()) notifyItemChanged(position, ImageSelectedOrUpdated())

View file

@ -1,10 +1,13 @@
package fr.free.nrw.commons.customselector.ui.selector package fr.free.nrw.commons.customselector.ui.selector
import android.app.Activity import android.app.Activity
import android.app.Dialog
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.view.Window
import android.widget.Button
import android.widget.ImageButton import android.widget.ImageButton
import android.widget.TextView import android.widget.TextView
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
@ -16,6 +19,7 @@ import fr.free.nrw.commons.theme.BaseActivity
import java.io.File import java.io.File
import javax.inject.Inject import javax.inject.Inject
/** /**
* Custom Selector Activity. * Custom Selector Activity.
*/ */
@ -55,10 +59,18 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
setContentView(R.layout.activity_custom_selector) setContentView(R.layout.activity_custom_selector)
prefs = applicationContext.getSharedPreferences("CustomSelector", MODE_PRIVATE) prefs = applicationContext.getSharedPreferences("CustomSelector", MODE_PRIVATE)
viewModel = ViewModelProvider(this, customSelectorViewModelFactory).get(CustomSelectorViewModel::class.java) viewModel = ViewModelProvider(this, customSelectorViewModelFactory).get(
CustomSelectorViewModel::class.java
)
setupViews() setupViews()
if(prefs.getBoolean("customSelectorFirstLaunch", true)) {
// show welcome dialog on first launch
showWelcomeDialog()
prefs.edit().putBoolean("customSelectorFirstLaunch", false).apply()
}
// Open folder if saved in prefs. // Open folder if saved in prefs.
if(prefs.contains(FOLDER_ID)){ if(prefs.contains(FOLDER_ID)){
val lastOpenFolderId: Long = prefs.getLong(FOLDER_ID, 0L) val lastOpenFolderId: Long = prefs.getLong(FOLDER_ID, 0L)
@ -68,6 +80,17 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
} }
} }
/**
* Show Custom Selector Welcome Dialog.
*/
private fun showWelcomeDialog() {
val dialog = Dialog(this)
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog.setContentView(R.layout.custom_selector_info_dialog)
(dialog.findViewById(R.id.btn_ok) as Button).setOnClickListener { dialog.dismiss() }
dialog.show()
}
/** /**
* Set up view, default folder view. * Set up view, default folder view.
*/ */

View file

@ -0,0 +1,133 @@
<?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_height="wrap_content"
android:layout_width="match_parent"
android:layout_margin="@dimen/dimen_10">
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/welcome_custom_picture_selector_text"
android:textSize="@dimen/normal_text"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/dimen_10"
android:text="@string/custom_selector_info_text1"
android:textSize="@dimen/description_text_size"
android:textStyle="bold"/>
<LinearLayout
android:layout_marginHorizontal="@dimen/dimen_10"
android:layout_width="match_parent"
android:layout_height="@dimen/dimen_150"
android:layout_gravity="center"
android:orientation="horizontal"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_weight="1"
android:layout_width="0dp"
android:padding="@dimen/dimen_2"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
app:cardCornerRadius="@dimen/dimen_6"
android:layout_height="match_parent"
app:cardElevation="@dimen/dimen_2"
android:id="@+id/view"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image_thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/welcome_image_example"/>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_weight="1"
android:layout_width="0dp"
android:padding="@dimen/dimen_2"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="@dimen/dimen_6"
app:cardElevation="@dimen/dimen_2"
android:id="@+id/view_uploaded"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image_thumbnail_uploaded"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/welcome_image_example"/>
<View
android:id="@+id/uploaded_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.15"
android:background="@color/black"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="203dp" />
<ImageView
android:id="@+id/uploaded_overlay_icon"
android:layout_width="@dimen/dimen_72"
android:layout_height="@dimen/dimen_72"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:srcCompat="@drawable/commons"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dimen_10"
android:gravity="center"
android:text="@string/custom_selector_info_text2"
android:textSize="@dimen/description_text_size"
android:textStyle="bold"/>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_ok"
android:layout_marginHorizontal="@dimen/dimen_40"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:text="@string/welcome_custom_selector_ok"
/>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -643,5 +643,10 @@ Upload your first media by tapping on the add button.</string>
<string name="custom_selector_empty_text">No Images</string> <string name="custom_selector_empty_text">No Images</string>
<string name="done">Done</string> <string name="done">Done</string>
<string name="back">Back</string> <string name="back">Back</string>
<string name="welcome_custom_picture_selector_text">Welcome to Custom Picture Selector</string>
<string name="custom_selector_info_text1">This picker shows differently pictures that are already to Commons.</string>
<string name="custom_selector_info_text2">Unlike the picture on the left, the picture on the right has the Commons logo indicating it is already uploaded.</string>
<string name="welcome_custom_selector_ok">Awesome</string>
<string name="custom_selector_already_uploaded_image_text">This image has already been uploaded to Commons.</string>
</resources> </resources>