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

Enhancment/update theme fragment #195

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ThemeFragment : Fragment(R.layout.fragment_theme) {
}
}

private val adapter = ThemeListAdapter(listener)
private val adapter = ThemeListAdapter(listener = listener)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand Down Expand Up @@ -300,7 +300,12 @@ class ThemeFragment : Fragment(R.layout.fragment_theme) {
)
)

val sharedPref = PreferenceManager.getDefaultSharedPreferences(context)
val currentTheme = sharedPref.getString(THEME_PREF, "original") ?: "original"
adapter.selectedTheme = currentTheme

adapter.addData(themeList)

// Set the adapter
themes.layoutManager = GridLayoutManager(context, 3)
themes.adapter = adapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package journal.gratitude.com.gratitudejournal.ui.themes

import android.view.LayoutInflater
import android.view.View
import android.view.View.OnClickListener
import android.view.View.*
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
Expand All @@ -11,7 +11,7 @@ import journal.gratitude.com.gratitudejournal.R
import journal.gratitude.com.gratitudejournal.model.Theme
import kotlinx.android.synthetic.main.item_theme.view.*

class ThemeListAdapter(private val listener: ThemeFragment.OnThemeSelectedListener?) :
class ThemeListAdapter(var selectedTheme: String = "original", private val listener: ThemeFragment.OnThemeSelectedListener?) :
ListAdapter<Theme, ThemeListAdapter.ThemeViewHolder>(ThemeDC()) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ThemeViewHolder(
Expand Down Expand Up @@ -51,6 +51,11 @@ class ThemeListAdapter(private val listener: ThemeFragment.OnThemeSelectedListen
timeline_line.setBackgroundColor(item.headerColor)
theme_name.text = item.name
theme_name.setTextColor(item.iconColor)

if(item.name.equals(selectedTheme))
selectIcon.visibility = VISIBLE
else
selectIcon.visibility = INVISIBLE
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class TimelineViewModel @Inject constructor(private val repository: EntryReposit
listWithHintsAndMilestones.add(0, Milestone.create(numEntries))
}
}

}
entries.value = listWithHintsAndMilestones
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
android:id="@+id/themes"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#AFAFAF"
android:layout_marginBottom="8dp"
android:background="?attr/backgroundColor"
android:padding="8dp"
app:layoutManager="LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down
159 changes: 90 additions & 69 deletions app/src/main/res/layout/item_theme.xml
Original file line number Diff line number Diff line change
@@ -1,81 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this LinearLayout needed for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alisonthemonster Hey, sorry for the late reply. It's used to create the border. The easiest implementation I know currently.

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:background="?attr/backgroundColor"
android:orientation="vertical"
android:padding="5dp">

<View
android:id="@+id/header"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF">

<View
android:id="@+id/background_view"
android:layout_width="0dp"
android:layout_height="170dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/header" />
<View
android:id="@+id/header"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/icon"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toBottomOf="@+id/background_view"
app:layout_constraintEnd_toEndOf="@+id/background_view"
app:layout_constraintStart_toEndOf="@+id/timeline_line"
app:layout_constraintTop_toBottomOf="@+id/theme_name"
app:srcCompat="@drawable/ic_flower" />
<View
android:id="@+id/background_view"
android:layout_width="0dp"
android:layout_height="170dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/header" />

<View
android:id="@+id/timeline_line"
android:layout_width="3dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:background="?attr/timelineLineColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/header" />
<ImageView
android:id="@+id/icon"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toBottomOf="@+id/background_view"
app:layout_constraintEnd_toEndOf="@+id/background_view"
app:layout_constraintStart_toEndOf="@+id/timeline_line"
app:layout_constraintTop_toBottomOf="@+id/theme_name"
app:srcCompat="@drawable/ic_flower" />

<TextView
android:id="@+id/theme_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="viewStart"
android:textSize="14dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/timeline_line"
app:layout_constraintTop_toBottomOf="@+id/header"
tools:text="January 19th, 2018" />
<View
android:id="@+id/timeline_line"
android:layout_width="3dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginBottom="8dp"
android:background="?attr/timelineLineColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/header" />

<TextView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/presently"
android:theme="@style/TextAppearance.Title"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="@+id/header"
app:layout_constraintEnd_toEndOf="@+id/header"
app:layout_constraintStart_toStartOf="@+id/header"
app:layout_constraintTop_toTopOf="@+id/header" />
<TextView
android:id="@+id/theme_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="viewStart"
android:textSize="14dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/timeline_line"
app:layout_constraintTop_toBottomOf="@+id/header"
tools:text="January 19th, 2018" />

<TextView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/presently"
android:textSize="18dp"
android:theme="@style/TextAppearance.Title"
app:layout_constraintBottom_toBottomOf="@+id/header"
app:layout_constraintEnd_toEndOf="@+id/header"
app:layout_constraintStart_toStartOf="@+id/header"
app:layout_constraintTop_toTopOf="@+id/header" />

<ImageView
android:id="@+id/selectIcon"
android:layout_width="56dp"
android:layout_height="42dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/checkbox_on_background" />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in order to merge this PR we'll need to find a different icon that matches the Presently style. I don't have the capacity right now to design something so this might have to wait a bit!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought so too. I had to get an icon on there for demonstration. We can change it once we find or design a suitable one. I'll leave that to you.
Just let me know when you get one. Really feel like this would be a huge and valuable addition to the next release.


</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>