-
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
a97fe71
commit 80fc945
Showing
15 changed files
with
304 additions
and
45 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
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
48 changes: 48 additions & 0 deletions
48
app/src/main/java/org/fossasia/badgemagic/ui/EditClipartActivity.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,48 @@ | ||
package org.fossasia.badgemagic.ui | ||
|
||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.lifecycle.Observer | ||
import kotlinx.android.synthetic.main.activity_edit_clipart.* | ||
import org.fossasia.badgemagic.R | ||
import org.fossasia.badgemagic.databinding.ActivityEditClipartBinding | ||
import org.fossasia.badgemagic.util.Converters | ||
import org.fossasia.badgemagic.util.StorageUtils | ||
import org.fossasia.badgemagic.viewmodels.EditClipartViewModel | ||
import org.koin.androidx.viewmodel.ext.android.viewModel | ||
|
||
class EditClipartActivity : AppCompatActivity() { | ||
|
||
private val editClipartViewModel by viewModel<EditClipartViewModel>() | ||
private lateinit var fileName: String | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val activityDrawBinding = DataBindingUtil.setContentView<ActivityEditClipartBinding>(this, R.layout.activity_edit_clipart) | ||
activityDrawBinding.viewModel = editClipartViewModel | ||
|
||
if (intent.hasExtra("fileName")) { | ||
fileName = intent?.extras?.getString("fileName") ?: "" | ||
editClipartViewModel.drawingJSON.set(Converters.convertDrawableToLEDHex(StorageUtils.getClipartFromPath(fileName), false)) | ||
} | ||
|
||
editClipartViewModel.savedButton.observe(this, Observer { | ||
if (it) { | ||
if (StorageUtils.saveEditedClipart(Converters.convertStringsToLEDHex(draw_layout.getCheckedList()), fileName)) { | ||
Toast.makeText(this, R.string.clipart_saved_success, Toast.LENGTH_LONG).show() | ||
editClipartViewModel.updateClipArts() | ||
} else | ||
Toast.makeText(this, R.string.clipart_saved_error, Toast.LENGTH_LONG).show() | ||
finish() | ||
} | ||
}) | ||
|
||
editClipartViewModel.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
48 changes: 48 additions & 0 deletions
48
app/src/main/java/org/fossasia/badgemagic/viewmodels/EditClipartViewModel.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,48 @@ | ||
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 EditClipartViewModel( | ||
private val clipArtService: ClipArtService | ||
) : ViewModel() { | ||
var drawModeState: ObservableField<DrawMode> = ObservableField(DrawMode.NOTHING) | ||
var drawingJSON: ObservableField<List<String>> = ObservableField(listOf()) | ||
|
||
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() | ||
} |
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
Oops, something went wrong.