-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from machbarschaft/home_activity
feature: Add home fragment
- Loading branch information
Showing
12 changed files
with
347 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package jetzt.machbarschaft.android.data | ||
|
||
// TODO add all order attributes | ||
data class Order(val id: String) |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/jetzt/machbarschaft/android/util/ReportProblemUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package jetzt.machbarschaft.android.util | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Build | ||
import jetzt.machbarschaft.android.BuildConfig | ||
import jetzt.machbarschaft.android.R | ||
|
||
fun getBugMailIntent(context: Context) = | ||
Intent( | ||
Intent.ACTION_VIEW, Uri.parse( | ||
"mailto:[email protected]" + | ||
"?subject=" + context.getString(R.string.home_feedback_subject) + | ||
"&body=" + context.getString(R.string.home_feedback_body1) + | ||
"\nVersion-Name: " + BuildConfig.VERSION_NAME + | ||
"\nVersion-Code: " + BuildConfig.VERSION_CODE + | ||
"\nAndroid-Version: " + Build.DISPLAY + | ||
"\nDevice: " + Build.DEVICE + | ||
"\nManufacturer: " + Build.MANUFACTURER + | ||
"\nModel: " + Build.MODEL + | ||
"\n\n" + context.getString(R.string.home_feedback_body2) | ||
) | ||
) |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/jetzt/machbarschaft/android/view/activities/HomeActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package jetzt.machbarschaft.android.view.activities | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import jetzt.machbarschaft.android.R | ||
|
||
class HomeActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_home) | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
app/src/main/java/jetzt/machbarschaft/android/view/home/HomeFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package jetzt.machbarschaft.android.view.home | ||
|
||
import android.app.AlertDialog | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import android.widget.TextView | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.viewModels | ||
import androidx.lifecycle.observe | ||
import com.google.android.material.tabs.TabLayout | ||
import jetzt.machbarschaft.android.R | ||
import jetzt.machbarschaft.android.util.getBugMailIntent | ||
|
||
class HomeFragment : Fragment() { | ||
companion object { | ||
fun newInstance() = HomeFragment() | ||
const val LOG_TAG = "HomeFragment" | ||
} | ||
|
||
private lateinit var viewModel: HomeViewModel | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
return inflater.inflate(R.layout.fragment_home, container, false) | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val model: HomeViewModel by viewModels() | ||
viewModel = model | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
setupSortingTabs(view) | ||
setupBottomButtons(view) | ||
setupObservers(view) | ||
} | ||
|
||
private fun setupSortingTabs(view: View) { | ||
view.findViewById<TabLayout>(R.id.sorting_tab_layout)?.apply { | ||
for (sortBy in HomeViewModel.SortBy.values()) { | ||
addTab(newTab().also { | ||
it.tag = sortBy | ||
it.text = getString(sortBy.text) | ||
}) | ||
} | ||
addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { | ||
override fun onTabSelected(tab: TabLayout.Tab?) { | ||
val tag = tab?.tag | ||
check(tag is HomeViewModel.SortBy) { "Sorting tab tag is invalid!" } | ||
Log.d(LOG_TAG, "Sorting orders by ${tag.name}") | ||
viewModel.onSortByChanged(tag) | ||
} | ||
|
||
override fun onTabReselected(tab: TabLayout.Tab?) {} | ||
|
||
override fun onTabUnselected(tab: TabLayout.Tab?) {} | ||
}) | ||
} | ||
} | ||
|
||
private fun setupBottomButtons(view: View) { | ||
view.findViewById<Button>(R.id.home_btn_faq)?.apply { | ||
setOnClickListener { | ||
startActivity( | ||
Intent(Intent.ACTION_VIEW, Uri.parse("https://machbarschaft.jetzt/faq.html")) | ||
) | ||
} | ||
} | ||
|
||
view.findViewById<Button>(R.id.home_btn_contact)?.apply { | ||
setOnClickListener { | ||
startActivity( | ||
Intent(Intent.ACTION_VIEW, Uri.parse("https://machbarschaft.jetzt/#contact")) | ||
) | ||
} | ||
} | ||
|
||
view.findViewById<Button>(R.id.home_btn_bug_report)?.apply { | ||
setOnClickListener { | ||
AlertDialog.Builder(context).run { | ||
setMessage(R.string.home_feedback_description) | ||
setCancelable(false) | ||
setPositiveButton(R.string.home_feedback_write_mail) { _, _ -> | ||
startActivity(getBugMailIntent(context)) | ||
} | ||
setNegativeButton(R.string.home_feedback_later) { dialog, _ -> dialog.dismiss() } | ||
}.create().show() | ||
} | ||
} | ||
} | ||
|
||
private fun setupObservers(view: View) { | ||
viewModel.getOrders().observe(viewLifecycleOwner) { orders -> | ||
view.findViewById<TextView>(R.id.order_count_text)?.apply { | ||
text = resources.getQuantityString( | ||
R.plurals.home_order_count, | ||
orders.size, | ||
orders.size | ||
) | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/jetzt/machbarschaft/android/view/home/HomeViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package jetzt.machbarschaft.android.view.home | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import jetzt.machbarschaft.android.R | ||
import jetzt.machbarschaft.android.data.Order | ||
|
||
class HomeViewModel : ViewModel() { | ||
private val orders: MutableLiveData<List<Order>> by lazy { | ||
MutableLiveData<List<Order>>(emptyList()).also { | ||
loadOrders() | ||
} | ||
} | ||
|
||
fun getOrders(): LiveData<List<Order>> { | ||
return orders | ||
} | ||
|
||
fun onSortByChanged(sortBy: SortBy) { | ||
// TODO update orders | ||
} | ||
|
||
private fun loadOrders() { | ||
// TODO load orders | ||
} | ||
|
||
enum class SortBy(@StringRes val text: Int) { | ||
DISTANCE(R.string.home_tab_distance), | ||
URGENCY(R.string.home_tab_urgency) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout 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=".view.activities.HomeActivity"> | ||
|
||
<fragment | ||
android:id="@+id/fragment_container_home" | ||
android:name="androidx.navigation.fragment.NavHostFragment" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:defaultNavHost="true" | ||
app:navGraph="@navigation/nav_graph_home" /> | ||
|
||
</LinearLayout> |
Oops, something went wrong.