-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
244 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
90 changes: 90 additions & 0 deletions
90
app/src/main/java/com/albatros/kplanner/ui/fragments/profile/ProfileFragment.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,90 @@ | ||
package com.albatros.kplanner.ui.fragments.profile | ||
|
||
import android.animation.ArgbEvaluator | ||
import android.animation.ValueAnimator | ||
import android.os.Bundle | ||
import android.transition.TransitionInflater | ||
import android.view.* | ||
import android.widget.ImageView | ||
import android.widget.Toast | ||
import androidx.cardview.widget.CardView | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.fragment.navArgs | ||
import androidx.recyclerview.widget.ItemTouchHelper | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.albatros.kplanner.R | ||
import com.albatros.kplanner.databinding.ProfileFragmentBinding | ||
import com.albatros.kplanner.domain.getMonth | ||
import com.albatros.kplanner.domain.playFadeInAnimation | ||
import com.albatros.kplanner.model.data.DiraNote | ||
import com.albatros.kplanner.model.data.Schedule | ||
import com.albatros.kplanner.ui.activity.MainActivity | ||
import com.albatros.kplanner.ui.adapter.schedule.ScheduleAdapter | ||
import com.albatros.kplanner.ui.adapter.schedule.ScheduleAdapterListener | ||
import org.koin.androidx.viewmodel.ext.android.viewModel | ||
import org.koin.core.parameter.parametersOf | ||
import java.util.* | ||
|
||
class ProfileFragment : Fragment() { | ||
|
||
private val viewModel: ProfileViewModel by viewModel { parametersOf(arguments.user) } | ||
private lateinit var binding: ProfileFragmentBinding | ||
private val arguments: ProfileFragmentArgs by navArgs() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
binding = ProfileFragmentBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { | ||
inflater.inflate(R.menu.profile_menu, menu) | ||
super.onCreateOptionsMenu(menu, inflater) | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean = when(item.itemId) { | ||
R.id.action_import -> { | ||
viewModel.importSchedule() | ||
true | ||
} else -> false | ||
} | ||
|
||
private val listener = object: ScheduleAdapterListener { | ||
|
||
override fun OnFirstNoteBinded(view: CardView) {} | ||
|
||
override fun onNoteFinished(note: DiraNote, schedule: Schedule, view: ImageView) {} | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
setHasOptionsMenu(true) | ||
|
||
postponeEnterTransition() | ||
sharedElementEnterTransition = | ||
TransitionInflater.from(context).inflateTransition(android.R.transition.move) | ||
startPostponedEnterTransition() | ||
|
||
viewModel.onImported.observe(viewLifecycleOwner) { | ||
if (it) { | ||
(activity as MainActivity).binding.toolbar.menu.findItem(R.id.action_import).setIcon(R.drawable.ic_check) | ||
} | ||
} | ||
|
||
viewModel.userSchedule.observe(viewLifecycleOwner) { | ||
binding.list.adapter = ScheduleAdapter(it, listener) | ||
binding.list.layoutManager = LinearLayoutManager(context) | ||
val calendar = Calendar.getInstance() | ||
binding.date.text = context?.getString( | ||
R.string.date_str, | ||
calendar.get(Calendar.DAY_OF_MONTH), | ||
getMonth(calendar.get(Calendar.MONTH)) | ||
) | ||
binding.date.playFadeInAnimation(500L) | ||
} | ||
|
||
(activity as MainActivity).binding.toolbar.title = arguments.user.nickname | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/com/albatros/kplanner/ui/fragments/profile/ProfileViewModel.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,37 @@ | ||
package com.albatros.kplanner.ui.fragments.profile | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.albatros.kplanner.model.api.DiraApi | ||
import com.albatros.kplanner.model.data.DiraUser | ||
import com.albatros.kplanner.model.data.Schedule | ||
import com.albatros.kplanner.model.repo.UserRepo | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
class ProfileViewModel(private val repo: UserRepo, private val api: DiraApi, private val chosen: DiraUser) : ViewModel() { | ||
|
||
private val _userSchedule: MutableLiveData<Schedule> = MutableLiveData<Schedule>().apply { | ||
viewModelScope.launch(Dispatchers.Main) { | ||
value = api.getScheduleByOwnerId(chosen.tokenId) | ||
} | ||
} | ||
|
||
val userSchedule: LiveData<Schedule> = _userSchedule | ||
|
||
private val _onImported: MutableLiveData<Boolean> = MutableLiveData(false) | ||
val onImported: LiveData<Boolean> = _onImported | ||
|
||
fun importSchedule() { | ||
viewModelScope.launch(Dispatchers.Main) { | ||
val schedule = api.getScheduleByOwnerId(chosen.tokenId).copy(ownerId = repo.diraUser.tokenId) | ||
schedule.tasks.forEach { it.finished = false } | ||
api.createSchedule(schedule) | ||
repo.schedule = schedule | ||
_onImported.value = true | ||
} | ||
} | ||
|
||
} |
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,5 @@ | ||
<vector android:height="32dp" android:tint="@color/dark_cyan" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM17,13l-5,5 -5,-5h3V9h4v4h3z"/> | ||
</vector> |
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,59 @@ | ||
<?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"> | ||
|
||
<androidx.core.widget.NestedScrollView | ||
android:id="@+id/scroll_content" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:visibility="visible" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
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="match_parent" | ||
android:minWidth="600dp" | ||
android:orientation="vertical" | ||
android:paddingStart="8dp" | ||
android:paddingEnd="8dp"> | ||
|
||
<TextView | ||
android:id="@+id/date" | ||
style="@style/NoteCardTextStyleData" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Сегодня, 3 июля" | ||
android:layout_marginTop="24dp" | ||
android:visibility="invisible" | ||
android:gravity="center" | ||
android:textColor="@color/dark_cyan" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/list" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_gravity="start" | ||
android:layout_marginTop="8dp" | ||
android:overScrollMode="never" | ||
|
||
android:gravity="start" | ||
android:minHeight="700dp" | ||
android:orientation="vertical" | ||
android:paddingBottom="300dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/date" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
</androidx.core.widget.NestedScrollView> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<item | ||
android:id="@+id/action_import" | ||
android:orderInCategory="1" | ||
android:title="@string/app_name" | ||
android:icon="@drawable/ic_import" | ||
app:showAsAction="always" /> | ||
</menu> |
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