-
Notifications
You must be signed in to change notification settings - Fork 220
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
1 parent
dd6c926
commit 28096f6
Showing
17 changed files
with
366 additions
and
24 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
9 changes: 9 additions & 0 deletions
9
app/src/main/java/org/fossasia/badgemagic/extensions/ActivityExtensions.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,9 @@ | ||
package org.fossasia.badgemagic.extensions | ||
|
||
import android.app.Activity | ||
import androidx.annotation.Keep | ||
|
||
@Keep | ||
fun <A : Activity> A.setRotation(rotation: Int) { | ||
this.requestedOrientation = rotation | ||
} |
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
53 changes: 53 additions & 0 deletions
53
app/src/main/java/org/fossasia/badgemagic/ui/fragments/DrawFragment.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,53 @@ | ||
package org.fossasia.badgemagic.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Toast | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.lifecycle.Observer | ||
import kotlinx.android.synthetic.main.fragment_draw.* | ||
import org.fossasia.badgemagic.R | ||
import org.fossasia.badgemagic.databinding.FragmentDrawBinding | ||
import org.fossasia.badgemagic.ui.base.BaseFragment | ||
import org.fossasia.badgemagic.util.Converters | ||
import org.fossasia.badgemagic.util.StorageUtils | ||
import org.fossasia.badgemagic.viewmodels.DrawViewModel | ||
import org.koin.androidx.viewmodel.ext.android.viewModel | ||
|
||
class DrawFragment : BaseFragment() { | ||
|
||
companion object { | ||
@JvmStatic | ||
fun newInstance() = | ||
DrawFragment() | ||
} | ||
|
||
private val viewModel by viewModel<DrawViewModel>() | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
val binding = DataBindingUtil.inflate<FragmentDrawBinding>(inflater, R.layout.fragment_draw, container, false) | ||
binding.viewModel = viewModel | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
viewModel.savedButton.observe(this, Observer { | ||
if (it) { | ||
if (StorageUtils.saveClipArt(Converters.convertStringsToLEDHex(draw_layout.getCheckedList()))) | ||
Toast.makeText(requireContext(), R.string.clipart_saved_success, Toast.LENGTH_LONG).show() | ||
else | ||
Toast.makeText(requireContext(), R.string.clipart_saved_error, Toast.LENGTH_LONG).show() | ||
} | ||
}) | ||
|
||
viewModel.resetButton.observe(this, Observer { | ||
if (it) { | ||
draw_layout.resetCheckListWithDummyData() | ||
} | ||
}) | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
app/src/main/java/org/fossasia/badgemagic/viewmodels/DrawViewModel.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,47 @@ | ||
package org.fossasia.badgemagic.viewmodels | ||
|
||
import androidx.databinding.ObservableBoolean | ||
import androidx.databinding.ObservableField | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import org.fossasia.badgemagic.data.draw_layout.DrawMode | ||
import org.fossasia.badgemagic.database.ClipArtService | ||
|
||
class DrawViewModel( | ||
private val clipArtService: ClipArtService | ||
) : ViewModel() { | ||
var drawModeState: ObservableField<DrawMode> = ObservableField(DrawMode.NOTHING) | ||
|
||
var drawState: ObservableBoolean = ObservableBoolean(false) | ||
var eraseState: ObservableBoolean = ObservableBoolean(false) | ||
|
||
var savedButton: MutableLiveData<Boolean> = MutableLiveData() | ||
var resetButton: MutableLiveData<Boolean> = MutableLiveData() | ||
|
||
init { | ||
savedButton.value = false | ||
resetButton.value = false | ||
} | ||
|
||
fun changeDrawState() { | ||
drawState.set(!drawState.get()) | ||
eraseState.set(false) | ||
drawModeState.set(if (drawState.get()) DrawMode.DRAW else DrawMode.NOTHING) | ||
} | ||
|
||
fun changeEraseState() { | ||
eraseState.set(!eraseState.get()) | ||
drawState.set(false) | ||
drawModeState.set(if (eraseState.get()) DrawMode.ERASE else DrawMode.NOTHING) | ||
} | ||
|
||
fun saveBadge() { | ||
savedButton.value = true | ||
} | ||
|
||
fun changeResetState() { | ||
resetButton.value = true | ||
} | ||
|
||
fun updateCliparts() = clipArtService.updateClipArts() | ||
} |
Oops, something went wrong.