content
stringlengths 0
3.9M
| path
stringlengths 4
242
| contentHash
stringlengths 1
10
|
---|---|---|
package lojas.longo.lojaslongoestoque.application.usecases
import lojas.longo.lojaslongoestoque.core.entity.User
interface FindUserByIdUseCase {
fun execute(id:Long): User?
} | ApiGestaoProdutosUsuarios/src/main/kotlin/api/cleancode/api/application/usecases/FindUserByIdUseCase.kt | 2897964224 |
// Pacote da Camada de Casos de Uso - Interface de Caso de Uso
package lojas.longo.lojaslongoestoque.application.usecases
import lojas.longo.lojaslongoestoque.core.entity.User
interface CreateUserUseCase {
fun execute(username: String, password: String): User
}
| ApiGestaoProdutosUsuarios/src/main/kotlin/api/cleancode/api/application/usecases/CreateUserUseCase.kt | 1644533174 |
package com.janceeabonita012.googleloginabonitaj
import android.os.Build
import android.os.Bundle
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate
import expo.modules.ReactActivityDelegateWrapper
class MainActivity : ReactActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// Set the theme to AppTheme BEFORE onCreate to support
// coloring the background, status bar, and navigation bar.
// This is required for expo-splash-screen.
setTheme(R.style.AppTheme);
super.onCreate(null)
}
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
override fun getMainComponentName(): String = "main"
/**
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
*/
override fun createReactActivityDelegate(): ReactActivityDelegate {
return ReactActivityDelegateWrapper(
this,
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED,
object : DefaultReactActivityDelegate(
this,
mainComponentName,
fabricEnabled
){})
}
/**
* Align the back button behavior with Android S
* where moving root activities to background instead of finishing activities.
* @see <a href="https://developer.android.com/reference/android/app/Activity#onBackPressed()">onBackPressed</a>
*/
override fun invokeDefaultOnBackPressed() {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
if (!moveTaskToBack(false)) {
// For non-root activities, use the default implementation to finish them.
super.invokeDefaultOnBackPressed()
}
return
}
// Use the default back button implementation on Android S
// because it's doing more than [Activity.moveTaskToBack] in fact.
super.invokeDefaultOnBackPressed()
}
}
| googlelogin-abonitaj/android/app/src/main/java/com/janceeabonita012/googleloginabonitaj/MainActivity.kt | 726339251 |
package com.janceeabonita012.googleloginabonitaj
import android.app.Application
import android.content.res.Configuration
import androidx.annotation.NonNull
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.ReactHost
import com.facebook.react.config.ReactFeatureFlags
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.flipper.ReactNativeFlipper
import com.facebook.soloader.SoLoader
import expo.modules.ApplicationLifecycleDispatcher
import expo.modules.ReactNativeHostWrapper
class MainApplication : Application(), ReactApplication {
override val reactNativeHost: ReactNativeHost = ReactNativeHostWrapper(
this,
object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> {
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return PackageList(this).packages
}
override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry"
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
}
)
override val reactHost: ReactHost
get() = getDefaultReactHost(this.applicationContext, reactNativeHost)
override fun onCreate() {
super.onCreate()
SoLoader.init(this, false)
if (!BuildConfig.REACT_NATIVE_UNSTABLE_USE_RUNTIME_SCHEDULER_ALWAYS) {
ReactFeatureFlags.unstable_useRuntimeSchedulerAlways = false
}
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
}
if (BuildConfig.DEBUG) {
ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager)
}
ApplicationLifecycleDispatcher.onApplicationCreate(this)
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig)
}
}
| googlelogin-abonitaj/android/app/src/main/java/com/janceeabonita012/googleloginabonitaj/MainApplication.kt | 208009141 |
package com.example.core
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.core.test", appContext.packageName)
}
} | GameIngpoh/core/src/androidTest/java/com/example/core/ExampleInstrumentedTest.kt | 3393852045 |
package com.example.core
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
} | GameIngpoh/core/src/test/java/com/example/core/ExampleUnitTest.kt | 2303082555 |
//package com.example.gameingpoh.core.ui
//
//import android.content.Context
//import androidx.lifecycle.ViewModel
//import androidx.lifecycle.ViewModelProvider
//import com.example.gameingpoh.detail.DetailGameViewModel
//import com.example.gameingpoh.favorite.FavoriteViewModel
//import com.example.gameingpoh.home.HomeViewModel
//import com.example.gameingpoh.core.di.Injection
//import com.example.gameingpoh.core.domain.usecase.GameUseCase
//
//class ViewModelFactory private constructor(private val gameUseCase: GameUseCase) :
//ViewModelProvider.NewInstanceFactory() {
//
// companion object{
// @Volatile
// private var instance: ViewModelFactory? = null
//
// fun getInstance(context: Context): ViewModelFactory =
// instance ?: synchronized(this) {
// instance ?: ViewModelFactory(
// Injection.provideTourismUseCase(context)
// )
// }
// }
//
//
// @Suppress("UNCHECKED_CAST")
// override fun <T : ViewModel> create(modelClass: Class<T>): T =
// when {
// modelClass.isAssignableFrom(HomeViewModel::class.java) -> {
// HomeViewModel(gameUseCase) as T
// }
// modelClass.isAssignableFrom(FavoriteViewModel::class.java) -> {
// FavoriteViewModel(gameUseCase) as T
// }
// modelClass.isAssignableFrom(DetailGameViewModel::class.java) -> {
// DetailGameViewModel(gameUseCase) as T
// }
// else -> throw Throwable("Unknown ViewModel class: " + modelClass.name)
// }
//} | GameIngpoh/core/src/main/java/com/example/core/ui/ViewModelFactory.kt | 3107636215 |
package com.example.core.ui
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.core.R
import com.example.core.databinding.ItemListBinding
import com.example.core.domain.model.Game
import java.util.ArrayList
class GameAdapter : RecyclerView.Adapter<GameAdapter.ListViewHolder>() {
private var listData = ArrayList<Game>()
var onItemClick: ((Game) -> Unit)? = null
fun setData(newListData: List<Game>?) {
if (newListData == null) return
listData.clear()
listData.addAll(newListData)
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
ListViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_list, parent, false))
override fun getItemCount() = listData.size
override fun onBindViewHolder(holder: ListViewHolder, position: Int) {
val data = listData[position]
holder.bind(data)
}
inner class ListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val binding = ItemListBinding.bind(itemView)
fun bind(data: Game) {
with(binding) {
Glide.with(itemView.context)
.load(data.backgroundImage)
.into(Cover)
tvTittle.text = data.name
tvReleaseDate.text = data.released
}
}
init {
binding.root.setOnClickListener {
onItemClick?.invoke(listData[adapterPosition])
}
}
}
} | GameIngpoh/core/src/main/java/com/example/core/ui/GameAdapter.kt | 4000799346 |
package com.example.core.di
import androidx.room.Room
import com.example.core.data.GameRepository
import com.example.core.data.source.local.LocalDataSource
import com.example.core.data.source.local.room.GameDatabase
import com.example.core.data.source.remote.RemoteDataSource
import com.example.core.data.source.remote.network.ApiService
import com.example.core.domain.repository.IGameRepository
import com.example.core.utils.AppExecutor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
val databaseModule = module {
factory { get<GameDatabase>().gameDao() }
single {
Room.databaseBuilder(
androidContext(),
GameDatabase::class.java, "Game.db"
).fallbackToDestructiveMigration().build()
}
}
val networkModule = module {
single {
OkHttpClient.Builder()
.addInterceptor { chain ->
val request = chain.request()
val url = request.url.newBuilder()
.addQueryParameter("key", "af0d00844b3e4675ac9dc61cbd264ffc")
.build()
val newRequest = request.newBuilder().url(url).build()
chain.proceed(newRequest)
}
.connectTimeout(120, TimeUnit.SECONDS)
.readTimeout(120, TimeUnit.SECONDS)
.build()
}
single {
val retrofit = Retrofit.Builder()
.baseUrl("https://api.rawg.io/api/")
.addConverterFactory(GsonConverterFactory.create())
.client(get())
.build()
retrofit.create(ApiService::class.java)
}
}
val repositoryModule = module {
single { com.example.core.data.source.local.LocalDataSource(get()) }
single { RemoteDataSource(get()) }
factory { AppExecutor() }
single<IGameRepository> { com.example.core.data.GameRepository(get(), get(), get()) }
} | GameIngpoh/core/src/main/java/com/example/core/di/CoreModule.kt | 3875480642 |
package com.example.core.utils
import android.os.Handler
import android.os.Looper
import androidx.annotation.VisibleForTesting
import java.util.concurrent.Executor
import java.util.concurrent.Executors
class AppExecutor @VisibleForTesting constructor(
private val diskIO: Executor,
private val networkIO: Executor,
private val mainThread: Executor
) {
companion object {
private const val THREAD_COUNT = 3
}
constructor() : this(
Executors.newSingleThreadExecutor(),
Executors.newFixedThreadPool(THREAD_COUNT),
MainThreadExecutor()
)
fun diskIO(): Executor = diskIO
fun networkIO(): Executor = networkIO
fun mainThread(): Executor = mainThread
private class MainThreadExecutor : Executor {
private val mainThreadHandler = Handler(Looper.getMainLooper())
override fun execute(command: Runnable) {
mainThreadHandler.post(command)
}
}
} | GameIngpoh/core/src/main/java/com/example/core/utils/AppExecutor.kt | 2146129362 |
package com.example.core.utils
import com.example.core.data.source.local.entity.GameEntity
import com.example.core.data.source.remote.response.GameResponse
import com.example.core.domain.model.Game
object DataMapper {
fun mapResponseToEntities(input : List<GameResponse>): List<GameEntity> {
val gameList = ArrayList<GameEntity>()
input.map {
val game = GameEntity(
id = it.id,
name = it.name,
backgroundImage = it.backgroundImage,
released = it.released
)
gameList.add(game)
}
return gameList
}
fun mapEntitiesToDomain(input: List<GameEntity>): List<Game> =
input.map {
Game(
id = it.id,
name = it.name,
backgroundImage = it.backgroundImage,
released = it.released,
isFavorite = it.isFavorite
)
}
fun mapDomainToEntity(input : Game) = GameEntity(
id = input.id,
name = input.name,
backgroundImage = input.backgroundImage,
released = input.released
)
} | GameIngpoh/core/src/main/java/com/example/core/utils/DataMapper.kt | 3234904693 |
package com.example.core.data.source.local.room
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.example.core.data.source.local.entity.GameEntity
import kotlinx.coroutines.flow.Flow
@Dao
interface GameDao {
@Query("SELECT * FROM game")
fun getAllGame(): Flow<List<GameEntity>>
@Query("SELECT * FROM game where isFavorite = 1")
fun getFavoriteGame(): Flow<List<GameEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertGame(game: List<GameEntity>)
@Update
fun updateFavoriteGame(game: GameEntity)
}
| GameIngpoh/core/src/main/java/com/example/core/data/source/local/room/GameDao.kt | 995079662 |
package com.example.core.data.source.local.room
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.core.data.source.local.entity.GameEntity
@Database(entities = [GameEntity::class], version = 1, exportSchema = false)
abstract class GameDatabase : RoomDatabase() {
abstract fun gameDao(): GameDao
companion object {
@Volatile
private var INSTANCE: GameDatabase? = null
// fun getInstance(context: Context): GameDatabase =
// INSTANCE ?: synchronized(this) {
// val instance = Room.databaseBuilder(
// context.applicationContext,
// GameDatabase::class.java,
// "Game.db"
// )
// .fallbackToDestructiveMigration()
// .build()
// INSTANCE = instance
// instance
// }
}
} | GameIngpoh/core/src/main/java/com/example/core/data/source/local/room/GameDatabase.kt | 70516027 |
package com.example.core.data.source.local.entity
import androidx.annotation.NonNull
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "game")
data class GameEntity(
@PrimaryKey
@NonNull
@ColumnInfo(name = "id")
val id: Int,
@ColumnInfo(name = "background_image")
val backgroundImage: String,
@ColumnInfo(name = "name")
val name: String,
@ColumnInfo(name = "released")
val released: String,
@ColumnInfo(name = "isFavorite")
var isFavorite: Boolean = false
)
| GameIngpoh/core/src/main/java/com/example/core/data/source/local/entity/GameEntity.kt | 3485395584 |
package com.example.core.data.source.local
import com.example.core.data.source.local.entity.GameEntity
import com.example.core.data.source.local.room.GameDao
import kotlinx.coroutines.flow.Flow
class LocalDataSource(private val gameDao: GameDao) {
companion object {
private var instance: com.example.core.data.source.local.LocalDataSource? = null
// fun getInstance(gameDao: GameDao): LocalDataSource =
// instance ?: synchronized(this) {
// instance ?: LocalDataSource(gameDao)
// }
}
fun getAllGame(): Flow<List<GameEntity>> = gameDao.getAllGame()
fun getFavoriteGame(): Flow<List<GameEntity>> = gameDao.getFavoriteGame()
suspend fun insertGame(tourismList: List<GameEntity>) = gameDao.insertGame(tourismList)
fun setFavoriteGame(tourism: GameEntity, newState: Boolean) {
tourism.isFavorite = newState
gameDao.updateFavoriteGame(tourism)
}
} | GameIngpoh/core/src/main/java/com/example/core/data/source/local/LocalDataSource.kt | 4169875315 |
package com.example.core.data.source.remote.response
import com.google.gson.annotations.SerializedName
data class ListGameResponse(
@SerializedName("count")
val count: Int,
@SerializedName("next")
val next: String,
@SerializedName("previous")
val previous: String,
@SerializedName("results")
val results: List<GameResponse>
)
data class GameResponse(
@SerializedName("id")
val id: Int,
@SerializedName("slug")
val slug: String,
@SerializedName("name")
val name: String,
@SerializedName("released")
val released: String,
@SerializedName("tba")
val tba: Boolean,
@SerializedName("background_image")
val backgroundImage: String,
@SerializedName("rating")
val rating: Double,
@SerializedName("rating_top")
val ratingTop: Int,
@SerializedName("ratings")
val ratings: Array<Any>, // You may need to adjust this based on the actual structure
@SerializedName("ratings_count")
val ratingsCount: Int,
@SerializedName("reviews_text_count")
val reviewsTextCount: String,
@SerializedName("added")
val added: Int,
@SerializedName("added_by_status")
val addedByStatus: Map<String, Any>, // You may need to adjust this based on the actual structure
@SerializedName("metacritic")
val metacritic: Int,
@SerializedName("playtime")
val playtime: Int,
@SerializedName("suggestions_count")
val suggestionsCount: Int,
@SerializedName("updated")
val updated: String,
@SerializedName("esrb_rating")
val esrbRating: EsrbRating, // Adjust this based on the actual structure
@SerializedName("platforms")
val platforms: List<Platform> // Adjust this based on the actual structure
)
data class EsrbRating(
@SerializedName("id")
val id: Int,
@SerializedName("slug")
val slug: String,
@SerializedName("name")
val name: String
)
data class Platform(
@SerializedName("platform")
val platform: PlatformInfo,
@SerializedName("released_at")
val releasedAt: String,
@SerializedName("requirements")
val requirements: Requirements // Adjust this based on the actual structure
)
data class PlatformInfo(
@SerializedName("id")
val id: Int,
@SerializedName("slug")
val slug: String,
@SerializedName("name")
val name: String
)
data class Requirements(
@SerializedName("minimum")
val minimum: String,
@SerializedName("recommended")
val recommended: String
)
| GameIngpoh/core/src/main/java/com/example/core/data/source/remote/response/Response.kt | 3617659661 |
package com.example.core.data.source.remote
import android.util.Log
import com.example.core.data.source.remote.network.ApiResponse
import com.example.core.data.source.remote.network.ApiService
import com.example.core.data.source.remote.response.GameResponse
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
class RemoteDataSource(private val apiService: ApiService) {
companion object {
@Volatile
private var instance: RemoteDataSource? = null
// fun getInstance(service: ApiService): RemoteDataSource =
// instance ?: synchronized(this) {
// instance ?: RemoteDataSource(service)
// }
}
suspend fun getAllTourism(): Flow<ApiResponse<List<GameResponse>>> {
//get data from remote api
return flow {
try {
val response = apiService.getList()
val dataArray = response.results
if (dataArray.isNotEmpty()){
emit(ApiResponse.Success(response.results))
} else {
emit(ApiResponse.Empty)
}
} catch (e : Exception){
emit(ApiResponse.Error(e.toString()))
Log.e("RemoteDataSource", e.toString())
}
}.flowOn(Dispatchers.IO)
}
}
| GameIngpoh/core/src/main/java/com/example/core/data/source/remote/RemoteDataSource.kt | 3345757876 |
package com.example.core.data.source.remote.network
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
object ApiConfig {
private const val BASE_URL = "https://api.rawg.io/api/"
private const val API_KEY = "af0d00844b3e4675ac9dc61cbd264ffc"
private fun provideOkHttpClient(): OkHttpClient {
return OkHttpClient.Builder()
.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.addInterceptor { chain ->
val original = chain.request()
val originalHttpUrl = original.url
val url = originalHttpUrl.newBuilder()
.addQueryParameter("key", API_KEY)
.build()
val requestBuilder = original.newBuilder().url(url)
val request = requestBuilder.build()
chain.proceed(request)
}
.connectTimeout(120, TimeUnit.SECONDS)
.readTimeout(120, TimeUnit.SECONDS)
.build()
}
fun provideApiService(): ApiService {
val retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(provideOkHttpClient())
.build()
return retrofit.create(ApiService::class.java)
}
}
| GameIngpoh/core/src/main/java/com/example/core/data/source/remote/network/ApiConfig.kt | 1180786381 |
package com.example.core.data.source.remote.network
import com.example.core.data.source.remote.response.ListGameResponse
import retrofit2.http.GET
interface ApiService {
@GET("games")
suspend fun getList(): ListGameResponse
} | GameIngpoh/core/src/main/java/com/example/core/data/source/remote/network/ApiService.kt | 785736169 |
package com.example.core.data.source.remote.network
sealed class ApiResponse<out R> {
data class Success<out T>(val data: T) : ApiResponse<T>()
data class Error(val errorMessage: String) : ApiResponse<Nothing>()
object Empty : ApiResponse<Nothing>()
}
| GameIngpoh/core/src/main/java/com/example/core/data/source/remote/network/ApiResponse.kt | 3871582813 |
package com.example.core.data
import com.example.core.data.source.local.LocalDataSource
import com.example.core.data.source.remote.RemoteDataSource
import com.example.core.data.source.remote.network.ApiResponse
import com.example.core.data.source.remote.response.GameResponse
import com.example.core.domain.model.Game
import com.example.core.domain.repository.IGameRepository
import com.example.core.utils.AppExecutor
import com.example.core.utils.DataMapper
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
class GameRepository(
private val remoteDataSource: RemoteDataSource,
private val localDataSource: com.example.core.data.source.local.LocalDataSource,
private val appExecutor: AppExecutor
) : IGameRepository {
companion object {
@Volatile
private var instance: com.example.core.data.GameRepository? = null
fun getInstance(
remoteData: RemoteDataSource,
localData: com.example.core.data.source.local.LocalDataSource,
appExecutors: AppExecutor
): com.example.core.data.GameRepository =
com.example.core.data.GameRepository.Companion.instance ?: synchronized(this) {
com.example.core.data.GameRepository.Companion.instance
?: com.example.core.data.GameRepository(remoteData, localData, appExecutors)
}
}
override fun getAllGame(): Flow<com.example.core.data.Resource<List<Game>>> =
object : com.example.core.data.NetworkBoundResource<List<Game>, List<GameResponse>>() {
override fun loadFromDB(): Flow<List<Game>> {
return localDataSource.getAllGame().map {
DataMapper.mapEntitiesToDomain(it)
}
}
override fun shouldFetch(data: List<Game>?): Boolean =
// data == null || data.isEmpty()
true // ganti dengan true jika ingin selalu mengambil data dari internet
override suspend fun createCall(): Flow<ApiResponse<List<GameResponse>>> =
remoteDataSource.getAllTourism()
override suspend fun saveCallResult(data: List<GameResponse>) {
val tourismList = DataMapper.mapResponseToEntities(data)
localDataSource.insertGame(tourismList)
}
}.asFlow()
override fun getFavoriteGame(): Flow<List<Game>> {
return localDataSource.getFavoriteGame().map {
DataMapper.mapEntitiesToDomain(it)
}
}
override fun setFavoriteGame(game: Game, state: Boolean) {
val gameEntity = DataMapper.mapDomainToEntity(game)
appExecutor.diskIO().execute { localDataSource.setFavoriteGame(gameEntity, state) }
}
} | GameIngpoh/core/src/main/java/com/example/core/data/GameRepository.kt | 2637290684 |
package com.example.core.data
sealed class Resource<T>(val data: T? = null, val message: String? = null) {
class Success<T>(data: T) : com.example.core.data.Resource<T>(data)
class Loading<T>(data: T? = null) : com.example.core.data.Resource<T>(data)
class Error<T>(message: String, data: T? = null) : com.example.core.data.Resource<T>(data, message)
} | GameIngpoh/core/src/main/java/com/example/core/data/Resource.kt | 2448502755 |
package com.example.core.data
import com.example.core.data.source.remote.network.ApiResponse
import kotlinx.coroutines.flow.*
abstract class NetworkBoundResource<ResultType, RequestType> {
private var result: Flow<com.example.core.data.Resource<ResultType>> = flow {
emit(com.example.core.data.Resource.Loading())
val dbSource = loadFromDB().first()
if (shouldFetch(dbSource)) {
emit(com.example.core.data.Resource.Loading())
when (val apiResponse = createCall().first()) {
is ApiResponse.Success -> {
saveCallResult(apiResponse.data)
emitAll(loadFromDB().map { com.example.core.data.Resource.Success(it) })
}
is ApiResponse.Empty -> {
emitAll(loadFromDB().map { com.example.core.data.Resource.Success(it) })
}
is ApiResponse.Error -> {
onFetchFailed()
emit(com.example.core.data.Resource.Error<ResultType>(apiResponse.errorMessage))
}
}
} else {
emitAll(loadFromDB().map { com.example.core.data.Resource.Success(it) })
}
}
protected open fun onFetchFailed() {}
protected abstract fun loadFromDB(): Flow<ResultType>
protected abstract fun shouldFetch(data: ResultType?): Boolean
protected abstract suspend fun createCall(): Flow<ApiResponse<RequestType>>
protected abstract suspend fun saveCallResult(data: RequestType)
fun asFlow(): Flow<com.example.core.data.Resource<ResultType>> = result
} | GameIngpoh/core/src/main/java/com/example/core/data/NetworkBoundResource.kt | 4294244322 |
package com.example.core.domain.repository
import com.example.core.data.Resource
import com.example.core.domain.model.Game
import kotlinx.coroutines.flow.Flow
interface IGameRepository {
fun getAllGame(): Flow<com.example.core.data.Resource<List<Game>>>
fun getFavoriteGame(): Flow<List<Game>>
fun setFavoriteGame(game: Game, state: Boolean)
} | GameIngpoh/core/src/main/java/com/example/core/domain/repository/IGameRepository.kt | 824739817 |
package com.example.core.domain.model
import android.os.Parcelable
import androidx.annotation.NonNull
import androidx.room.ColumnInfo
import androidx.room.PrimaryKey
import kotlinx.android.parcel.Parcelize
@Parcelize
data class Game(
val id: Int,
@ColumnInfo(name = "background_image")
val backgroundImage: String,
@ColumnInfo(name = "name")
val name: String,
@ColumnInfo(name = "released")
val released: String,
@ColumnInfo(name = "isFavorite")
var isFavorite: Boolean
) : Parcelable
| GameIngpoh/core/src/main/java/com/example/core/domain/model/Game.kt | 372794901 |
package com.example.core.domain.usecase
import com.example.core.data.Resource
import com.example.core.domain.model.Game
import kotlinx.coroutines.flow.Flow
interface GameUseCase {
fun getAllGame(): Flow<com.example.core.data.Resource<List<Game>>>
fun getFavoriteGame(): Flow<List<Game>>
fun setFavoriteGame(tourism: Game, state: Boolean)
} | GameIngpoh/core/src/main/java/com/example/core/domain/usecase/GameUseCase.kt | 2433717459 |
package com.example.core.domain.usecase
import com.example.core.data.GameRepository
import com.example.core.domain.model.Game
import com.example.core.domain.repository.IGameRepository
class GameInteractor(private val gameRepository: IGameRepository): GameUseCase {
override fun getAllGame() = gameRepository.getAllGame()
override fun getFavoriteGame() = gameRepository.getFavoriteGame()
override fun setFavoriteGame(tourism: Game, state: Boolean) = gameRepository.setFavoriteGame(tourism, state)
} | GameIngpoh/core/src/main/java/com/example/core/domain/usecase/TourismInteractor.kt | 3185846732 |
package com.example.gameingpoh
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.gameingpoh", appContext.packageName)
}
} | GameIngpoh/app/src/androidTest/java/com/example/gameingpoh/ExampleInstrumentedTest.kt | 2645203768 |
package com.example.gameingpoh
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
} | GameIngpoh/app/src/test/java/com/example/gameingpoh/ExampleUnitTest.kt | 1195630361 |
package com.example.gameingpoh.home
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import com.example.core.domain.usecase.GameUseCase
class HomeViewModel(tourismUseCase: GameUseCase) : ViewModel() {
val game = tourismUseCase.getAllGame().asLiveData()
} | GameIngpoh/app/src/main/java/com/example/gameingpoh/home/HomeViewModel.kt | 2673908830 |
package com.example.gameingpoh.home
import android.content.Intent
import androidx.lifecycle.ViewModelProvider
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.core.data.Resource
import com.example.core.ui.GameAdapter
//import com.example.gameingpoh.core.ui.ViewModelFactory
import com.example.gameingpoh.databinding.FragmentHomeBinding
import com.example.gameingpoh.detail.DetailGameActivity
import org.koin.androidx.viewmodel.ext.android.viewModel
class HomeFragment : Fragment() {
// private lateinit var homeViewModel: HomeViewModel
private val homeViewModel: HomeViewModel by viewModel()
private var _binding: FragmentHomeBinding? = null
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentHomeBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if (activity != null) {
val tourismAdapter = GameAdapter()
tourismAdapter.onItemClick = { selectedData ->
val intent = Intent(activity, DetailGameActivity::class.java)
intent.putExtra(DetailGameActivity.EXTRA_DATA, selectedData)
startActivity(intent)
}
// val factory = ViewModelFactory.getInstance(requireActivity())
// homeViewModel = ViewModelProvider(this, factory)[HomeViewModel::class.java]
homeViewModel.game.observe(viewLifecycleOwner, { game ->
if (game != null) {
when (game) {
is com.example.core.data.Resource.Loading -> binding.progressBar.visibility = View.VISIBLE
is com.example.core.data.Resource.Success -> {
binding.progressBar.visibility = View.GONE
tourismAdapter.setData(game.data)
}
is com.example.core.data.Resource.Error -> {
binding.progressBar.visibility = View.GONE
binding.viewError.root.visibility = View.VISIBLE
binding.viewError.tvError.text = game.message ?: ("something wrong")
}
}
}
})
with(binding.rvGames) {
layoutManager = LinearLayoutManager(context)
setHasFixedSize(true)
adapter = tourismAdapter
}
}
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
} | GameIngpoh/app/src/main/java/com/example/gameingpoh/home/HomeFragment.kt | 88194440 |
package com.example.gameingpoh
import android.app.Application
import com.example.core.di.databaseModule
import com.example.core.di.networkModule
import com.example.core.di.repositoryModule
import com.example.gameingpoh.di.useCaseModule
import com.example.gameingpoh.di.viewModelModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
import org.koin.core.logger.Level
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
startKoin {
androidLogger(Level.NONE)
androidContext(this@MyApplication)
modules(
listOf(
databaseModule,
networkModule,
repositoryModule,
useCaseModule,
viewModelModule
)
)
}
}
} | GameIngpoh/app/src/main/java/com/example/gameingpoh/MyApplication.kt | 3300416680 |
package com.example.gameingpoh
import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.core.view.GravityCompat
import androidx.fragment.app.Fragment
import com.example.gameingpoh.databinding.ActivityMainBinding
import com.example.gameingpoh.home.HomeFragment
import com.google.android.material.navigation.NavigationView
class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
val toggle = ActionBarDrawerToggle(
this,
binding.drawerLayout,
binding.appBarMain.toolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close
)
binding.drawerLayout.addDrawerListener(toggle)
toggle.syncState()
binding.navView.setNavigationItemSelectedListener(this)
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.replace(R.id.nav_host_fragment, HomeFragment())
.commit()
supportActionBar?.title = getString(R.string.app_name)
}
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
var fragment: Fragment? = null
var title = getString(R.string.app_name)
when (item.itemId) {
R.id.nav_home -> {
fragment = HomeFragment()
title = getString(R.string.app_name)
}
R.id.nav_favorite -> {
try {
val favoriteClassName = "com.example.favorite.FavoriteFragment"
val fragmentClass = Class.forName(favoriteClassName, false, classLoader)
fragment = fragmentClass.newInstance() as Fragment
} catch (e: Exception) {
Log.e("DynamicFragmentLoad", "Error loading fragment", e)
Toast.makeText(this, "Error loading fragment", Toast.LENGTH_SHORT).show()
}
}
}
if (fragment != null) {
supportFragmentManager.beginTransaction()
.replace(R.id.nav_host_fragment, fragment)
.commit()
}
supportActionBar?.title = title
binding.drawerLayout.closeDrawer(GravityCompat.START)
return true
}
} | GameIngpoh/app/src/main/java/com/example/gameingpoh/MainActivity.kt | 3655390862 |
package com.example.gameingpoh.di
import com.example.core.domain.usecase.GameInteractor
import com.example.core.domain.usecase.GameUseCase
import com.example.gameingpoh.detail.DetailGameViewModel
import com.example.gameingpoh.home.HomeViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module
val useCaseModule = module {
factory<GameUseCase> { GameInteractor(get()) }
}
val viewModelModule = module {
viewModel { HomeViewModel(get()) }
// viewModel { com.example.favorite.FavoriteViewModel(get()) }
viewModel { DetailGameViewModel(get()) }
} | GameIngpoh/app/src/main/java/com/example/gameingpoh/di/appModule.kt | 1814622474 |
package com.example.gameingpoh.detail
import androidx.lifecycle.ViewModel
import com.example.core.domain.model.Game
import com.example.core.domain.usecase.GameUseCase
class DetailGameViewModel (private val tourismUseCase: GameUseCase) : ViewModel() {
fun setFavoriteGame(game: Game, newStatus:Boolean) =
tourismUseCase.setFavoriteGame(game, newStatus)
} | GameIngpoh/app/src/main/java/com/example/gameingpoh/detail/DetailGameViewModel.kt | 3012138571 |
package com.example.gameingpoh.detail
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.core.content.ContextCompat
import androidx.lifecycle.ViewModelProvider
import com.bumptech.glide.Glide
import com.example.core.domain.model.Game
import com.example.gameingpoh.R
//import com.example.gameingpoh.core.ui.ViewModelFactory
import com.example.gameingpoh.databinding.ActivityDetailGameBinding
import org.koin.androidx.viewmodel.ext.android.viewModel
class DetailGameActivity : AppCompatActivity() {
companion object {
const val EXTRA_DATA = "extra_data"
}
// private lateinit var detailTourismViewModel: DetailGameViewModel
private val detailTourismViewModel: DetailGameViewModel by viewModel()
private lateinit var binding: ActivityDetailGameBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityDetailGameBinding.inflate(layoutInflater)
setContentView(binding.root)
// val factory = ViewModelFactory.getInstance(this)
// detailTourismViewModel = ViewModelProvider(this, factory)[DetailGameViewModel::class.java]
val detailTourism = intent.getParcelableExtra<Game>(EXTRA_DATA)
showDetailTourism(detailTourism)
}
private fun showDetailTourism(detailGame: Game?) {
detailGame?.let {
supportActionBar?.title = detailGame.name
binding.content.tvDetailDescription.text = detailGame.name
Glide.with(this@DetailGameActivity)
.load(detailGame.backgroundImage)
.into(binding.ivDetailImage)
var statusFavorite = detailGame.isFavorite
setStatusFavorite(statusFavorite)
binding.fab.setOnClickListener {
statusFavorite = !statusFavorite
detailTourismViewModel.setFavoriteGame(detailGame, statusFavorite)
setStatusFavorite(statusFavorite)
}
}
}
private fun setStatusFavorite(statusFavorite: Boolean) {
if (statusFavorite) {
binding.fab.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_favorite_yes))
} else {
binding.fab.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_favorite_no))
}
}
} | GameIngpoh/app/src/main/java/com/example/gameingpoh/detail/DetailGameActivity.kt | 983289155 |
package com.example.favorite
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.favorite", appContext.packageName)
}
} | GameIngpoh/favorite/src/androidTest/java/com/example/favorite/ExampleInstrumentedTest.kt | 3624269527 |
package com.example.favorite
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
} | GameIngpoh/favorite/src/test/java/com/example/favorite/ExampleUnitTest.kt | 509106448 |
package com.example.favorite
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import com.example.core.domain.usecase.GameUseCase
class FavoriteViewModel(gameuseCase: GameUseCase) : ViewModel() {
val favoriteGame = gameuseCase.getFavoriteGame().asLiveData()
}
| GameIngpoh/favorite/src/main/java/com/example/favorite/FavoriteViewModel.kt | 38312163 |
package com.example.favorite
import org.koin.androidx.viewmodel.compat.ScopeCompat.viewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module
val favoriteModule = module {
viewModel { FavoriteViewModel(get()) }
} | GameIngpoh/favorite/src/main/java/com/example/favorite/FavoriteModule.kt | 601998322 |
package com.example.favorite
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.core.ui.GameAdapter
import com.example.favorite.databinding.FragmentFavoriteBinding
//import com.example.gameingpoh.core.ui.ViewModelFactory
import com.example.gameingpoh.detail.DetailGameActivity
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.context.loadKoinModules
class FavoriteFragment : Fragment() {
// private lateinit var favoriteViewModel: FavoriteViewModel
private val favoriteViewModel: FavoriteViewModel by viewModel()
private var _binding: FragmentFavoriteBinding? = null
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentFavoriteBinding.inflate(inflater, container, false)
loadKoinModules(favoriteModule)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if (activity != null) {
val tourismAdapter = GameAdapter()
tourismAdapter.onItemClick = { selectedData ->
val intent = Intent(activity, DetailGameActivity::class.java)
intent.putExtra(DetailGameActivity.EXTRA_DATA, selectedData)
startActivity(intent)
}
// val factory = ViewModelFactory.getInstance(requireActivity())
// favoriteViewModel = ViewModelProvider(this, factory)[FavoriteViewModel::class.java]
favoriteViewModel.favoriteGame.observe(viewLifecycleOwner, { dataGame ->
tourismAdapter.setData(dataGame)
binding.viewEmpty.root.visibility = if (dataGame.isNotEmpty()) View.GONE else View.VISIBLE
})
with(binding.rvGame) {
layoutManager = LinearLayoutManager(context)
setHasFixedSize(true)
adapter = tourismAdapter
}
}
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
} | GameIngpoh/favorite/src/main/java/com/example/favorite/FavoriteFragment.kt | 1828258630 |
package com.example.laporanmasyarakat
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.laporanmasyarakat", appContext.packageName)
}
} | ProjectAkhirhalimah/app/src/androidTest/java/com/example/laporanmasyarakat/ExampleInstrumentedTest.kt | 3639383394 |
package com.example.laporanmasyarakat
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
} | ProjectAkhirhalimah/app/src/test/java/com/example/laporanmasyarakat/ExampleUnitTest.kt | 867775373 |
package com.example.laporanmasyarakat
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.ImageButton
class MainActivity : AppCompatActivity() {
private lateinit var btnjam: ImageButton
private lateinit var btntanggal: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setContentView(R.layout.activity_laporan)
btnjam = findViewById(R.id.btnJam)
btnjam.setOnClickListener {
startActivity(Intent(this,listkebakaranActivity2::class.java))
}
setContentView(R.layout.activity_main)
setContentView(R.layout.activity_laporan)
btntanggal = findViewById(R.id.btnTanggal)
btntanggal.setOnClickListener {
startActivity(Intent(this,listkebakaranActivity2::class.java))
}
}
} | ProjectAkhirhalimah/app/src/main/java/com/example/laporanmasyarakat/MainActivity.kt | 1977878162 |
package com.example.laporanmasyarakat
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
class riwayatActivity : AppCompatActivity() {
private lateinit var btn : Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_riwayat)
}
} | ProjectAkhirhalimah/app/src/main/java/com/example/laporanmasyarakat/riwayatActivity.kt | 1672818643 |
package com.example.laporanmasyarakat
import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
class RegisterActivity : AppCompatActivity() {
private lateinit var btnnew : Button
@SuppressLint("MissingInflatedId")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_register)
btnnew = findViewById(R.id.btnnew)
btnnew.setOnClickListener {
startActivity(Intent(this, LoginActivity::class.java))
}
}
}
| ProjectAkhirhalimah/app/src/main/java/com/example/laporanmasyarakat/RegisterActivity.kt | 3237445072 |
package com.example.laporanmasyarakat
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class listkebakaranActivity2 : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_riwayatlaporan)
}
} | ProjectAkhirhalimah/app/src/main/java/com/example/laporanmasyarakat/listkebakaranActivity2.kt | 3853737299 |
package com.example.laporanmasyarakat
import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.ImageButton
class DashboardActivity : AppCompatActivity() {
private lateinit var btngambar1 : ImageButton
private lateinit var btngambar2 : ImageButton
private lateinit var btngambar3 : ImageButton
private lateinit var btnriwayatlaporan :Button
@SuppressLint("MissingInflatedId")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dashboard)
btngambar1 = findViewById(R.id.btngambar1)
btngambar1.setOnClickListener {
startActivity(Intent(this, laporanActivity::class.java))
}
btngambar2 = findViewById(R.id.btngambar2)
btngambar2.setOnClickListener {
startActivity(Intent(this, laporanActivity::class.java))
}
btngambar3 = findViewById(R.id.btngambar3)
btngambar3.setOnClickListener {
startActivity(Intent(this, laporanActivity::class.java))
}
btnriwayatlaporan = findViewById(R.id.btnriwayatlaporan)
btnriwayatlaporan.setOnClickListener {
startActivity(Intent(this, riwayatActivity::class.java))
}
}
} | ProjectAkhirhalimah/app/src/main/java/com/example/laporanmasyarakat/DashboardActivity.kt | 3351255624 |
package com.example.laporanmasyarakat
import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
class LoginActivity : AppCompatActivity() {
private lateinit var btnlogin : Button
private lateinit var btnnew : Button
@SuppressLint("MissingInflatedId")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login2)
btnlogin = findViewById(R.id.btnlogin)
btnlogin.setOnClickListener {
startActivity(Intent(this, DashboardActivity::class.java))
}
btnnew = findViewById(R.id.btnnew)
btnnew.setOnClickListener {
startActivity(Intent(this ,RegisterActivity::class.java))
}
}
} | ProjectAkhirhalimah/app/src/main/java/com/example/laporanmasyarakat/LoginActivity.kt | 1939804491 |
package com.example.laporanmasyarakat
import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
class laporanActivity : AppCompatActivity() {
private lateinit var btnlaporan: Button
@SuppressLint("MissingInflatedId")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_laporan)
btnlaporan = findViewById(R.id.btnlaporan)
btnlaporan.setOnClickListener {
startActivity(Intent(this, listkebakaranActivity2::class.java))
}
}
} | ProjectAkhirhalimah/app/src/main/java/com/example/laporanmasyarakat/laporanActivity.kt | 1884786369 |
package com.minepacu.boothlistmanager
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.minepacu.boothlistmanager", appContext.packageName)
}
} | BoothListManager_ForAndroid/app/src/androidTest/java/com/minepacu/boothlistmanager/ExampleInstrumentedTest.kt | 237363980 |
package com.minepacu.boothlistmanager
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
} | BoothListManager_ForAndroid/app/src/test/java/com/minepacu/boothlistmanager/ExampleUnitTest.kt | 2425370821 |
package com.minepacu.boothlistmanager.boothList
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.minepacu.boothlistmanager.data.model.BoothInfo
import com.minepacu.boothlistmanager.R
class BoothsAdapter(private val onClick: (BoothInfo) -> Unit) :
ListAdapter<BoothInfo, BoothsAdapter.BoothViewHolder>(BoothDiffCallback){
class BoothViewHolder(itemView: View, val onClick: (BoothInfo) -> Unit) :
RecyclerView.ViewHolder(itemView) {
private val boothHeaderTextView: TextView = itemView.findViewById(R.id.boothNumber_Title_list)
private val boothSubTitleTextView: TextView = itemView.findViewById(R.id.boothGenre_list)
private var currentBooth: BoothInfo? = null
init {
itemView.setOnClickListener {
currentBooth?.let {
onClick(it)
}
}
}
fun bind(boothinfo: BoothInfo) {
currentBooth = boothinfo
val title_string = "${boothinfo.boothnumber}: ${boothinfo.boothname}"
val subtitle_string = "์ฅ๋ฅด: ${boothinfo.genres}"
boothHeaderTextView.text = title_string
boothSubTitleTextView.text = subtitle_string
}
}
override fun onCreateViewHolder(group: ViewGroup, viewType: Int): BoothViewHolder {
val view = LayoutInflater.from(group.context).inflate(R.layout.booth_item, group, false)
return BoothViewHolder(view, onClick)
}
override fun onBindViewHolder(holder: BoothViewHolder, position: Int) {
val boothinfo = getItem(position)
holder.bind(boothinfo)
}
}
object BoothDiffCallback: DiffUtil.ItemCallback<BoothInfo>() {
override fun areItemsTheSame(oldItem: BoothInfo, newItem: BoothInfo): Boolean {
return oldItem == newItem
}
override fun areContentsTheSame(oldItem: BoothInfo, newItem: BoothInfo): Boolean {
return oldItem.boothname == newItem.boothname
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/boothList/BoothsAdapter.kt | 2018111438 |
package com.minepacu.boothlistmanager.ui.Settings
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.minepacu.boothlistmanager.R
import com.minepacu.boothlistmanager.databinding.FragmentPreferenceBinding
class SettingsFragment : Fragment() {
private var _binding: FragmentPreferenceBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val slideshowViewModel =
ViewModelProvider(this).get(SettingsViewModel::class.java)
_binding = FragmentPreferenceBinding.inflate(inflater, container, false)
val root: View = binding.root
parentFragmentManager.beginTransaction()
.replace(R.id.preferences_layout, SettingsPreferenceFragment())
.commit()
return root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/ui/Settings/SettingsFragment.kt | 603733170 |
package com.minepacu.boothlistmanager.ui.Settings
import androidx.lifecycle.ViewModel
class SettingsViewModel : ViewModel() {
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/ui/Settings/SettingsViewModel.kt | 3972025019 |
package com.minepacu.boothlistmanager.ui.Settings
import android.content.SharedPreferences
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import com.chaquo.python.PyException
import com.minepacu.boothlistmanager.R
import com.minepacu.boothlistmanager.data.model.Result
import com.minepacu.boothlistmanager.tools.PythonCode.PythonClass
class SettingsPreferenceFragment : PreferenceFragmentCompat() {
lateinit var prefs: SharedPreferences
var sheetIdPreference: Preference? = null
var sheetNumberPreference: Preference? = null
var mail_order_sheetNumber: Preference? = null
var grasping_demand_sheetIndexPreference: Preference? = null
var updateSheetNumberPreference: Preference? = null
var update_mail_order_sheetIndex: Preference? = null
var update_grasping_demand_sheetIndex: Preference? = null
var sheetStartIndexPreference: Preference? = null
var sheetRowHeightPerLinePreference: Preference? = null
var updateSheetNamePreference: Preference? = null
var updateSheetStartIndexPreference: Preference? = null
var updateLogType: Preference? = null
var update_mail_order_sheetStartIndex: Preference? = null
var boothMapSheetIndexPreference: Preference? = null
var darkmode: Preference? = null
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preference, rootKey)
if (rootKey == null) {
sheetIdPreference = findPreference("sheetId")
sheetNumberPreference = findPreference("sheetNumber")
mail_order_sheetNumber = findPreference("mail_order_sheet_Index")
grasping_demand_sheetIndexPreference = findPreference("grasping_demand_sheet_Index")
updateSheetNumberPreference = findPreference("updateSheetNumber")
update_mail_order_sheetIndex = findPreference("update_mail_order_sheetIndex")
update_grasping_demand_sheetIndex = findPreference("update_grasping_demand_sheetIndex")
sheetStartIndexPreference = findPreference("sheetStartIndex")
sheetRowHeightPerLinePreference = findPreference("sheetRowHeightPerLine")
updateSheetNamePreference = findPreference("updateSheetName")
updateSheetStartIndexPreference = findPreference("updateSheetStartIndex")
updateLogType = findPreference("updateLogType")
update_mail_order_sheetStartIndex = findPreference("update_mail_order_SheetStartIndex")
boothMapSheetIndexPreference = findPreference("booth_map_sheet_Index")
darkmode = findPreference("DarkMode")
}
prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
}
val prefListener =
SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
when (key) {
// Category : General
"sheetId" -> {
val sheetId_Set = prefs.getString("sheetId", "")
try {
PythonClass.setVariable("sheetId", sheetId_Set)
} catch (e: PyException) {
Result.Error(Exception(e.message))
}
}
// Category : List_sheet_Index_Category
"sheetNumber" -> {
val sheetNumber_Set = prefs.getString("sheetNumber", "")
try {
PythonClass.setVariable("sheetNumber", sheetNumber_Set?.toInt())
} catch (e: PyException) {
Result.Error(Exception(e.message))
}
}
"mail_order_sheet_Index" -> {
val mail_order_sheet_Index_Set = prefs.getString("mail_order_sheet_Index", "")
try {
PythonClass.setVariable("mail_order_sheetIndex", mail_order_sheet_Index_Set)
} catch (e: PyException) {
Result.Error(Exception(e.message))
}
}
"grasping_demand_sheet_Index" -> {
}
// Category : update_log_sheet_Index_category
"updateSheetNumber" -> {
val updateSheetNumber_Set = prefs.getString("updateSheetNumber", "")
try {
PythonClass.setVariable("UpdateSheetNumber", updateSheetNumber_Set?.toInt())
} catch (e: PyException) {
Result.Error(Exception(e.message))
}
}
"update_mail_order_sheetIndex" -> {
val update_mail_order_sheetIndex_Set = prefs.getString("update_mail_order_sheetIndex", "")
try {
PythonClass.setVariable("update_mail_order_sheetIndex", update_mail_order_sheetIndex_Set)
} catch (e: PyException) {
Result.Error(Exception(e.message))
}
}
"update_grasping_demand_sheetIndex" -> {
}
// Category : list_sheet_category
"sheetStartIndex" -> {
val sheetStartIndex_Set = prefs.getString("sheetStartIndex", "")
try {
PythonClass.setVariable("sheetStartIndex", sheetStartIndex_Set?.toInt())
} catch (e: PyException) {
Result.Error(Exception(e.message))
}
}
"sheetRowHeightPerLine" -> {
val sheetRowHeightPerLine_Set = prefs.getString("sheetRowHeightPerLine", "")
try {
PythonClass.setVariable("sheetRowHeightPerLine", sheetRowHeightPerLine_Set?.toInt())
} catch (e: PyException) {
Result.Error(Exception(e.message))
}
}
// Category : update_category
"updateSheetName" -> {
val updateSheetName_Set = prefs.getString("updateSheetName", "")
try {
PythonClass.setVariable("UpdateLogSheetName", updateSheetName_Set)
} catch (e: PyException) {
Result.Error(Exception(e.message))
}
}
"updateSheetStartIndex" -> {
val updateSheetName_Set = prefs.getString("updateSheetStartIndex", "")
try {
PythonClass.setVariable("updateSheetStartIndex", updateSheetName_Set?.toInt())
} catch (e: PyException) {
Result.Error(Exception(e.message))
}
}
"updateLogType" -> {
val updateLogType_Set = prefs.getString("updateLogType", "")
try {
if (updateLogType_Set == "Custom") {
PythonClass.setVariable("updateLogType", 4)
} else {
PythonClass.setVariable("updateLogType", 1)
}
} catch (e: PyException) {
Result.Error(Exception(e.message))
}
}
// Category : update_mail_order_category
"update_mail_order_SheetStartIndex" -> {
val update_mail_order_sheetStartIndex_Set = prefs.getString("update_mail_order_sheetStartIndex", "")
try {
PythonClass.setVariable("update_mail_order_sheetStartIndex", update_mail_order_sheetStartIndex_Set)
} catch (e: PyException) {
Result.Error(Exception(e.message))
}
}
"booth_map_sheet_Index" -> {
val booth_map_sheet_Index_Set = prefs.getString("booth_map_sheet_Index", "")
try {
PythonClass.setVariable("MapSheetNumber", booth_map_sheet_Index_Set?.toInt())
} catch (e: PyException) {
Result.Error(PyException(e.message))
}
}
"DarkMode" -> {
}
}
}
val darkmodeListener = Preference.OnPreferenceChangeListener { _, new_value ->
if (new_value == true) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
true
} else if (new_value == false) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
true
} else {
Log.d("Debug", "new Value is $new_value")
false
}
}
override fun onResume() {
super.onResume()
prefs.registerOnSharedPreferenceChangeListener(prefListener)
darkmode?.onPreferenceChangeListener = darkmodeListener
}
override fun onPause() {
super.onPause()
prefs.unregisterOnSharedPreferenceChangeListener(prefListener)
darkmode?.onPreferenceChangeListener = null
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/ui/Settings/SettingsPreferenceFragment.kt | 3279890891 |
package com.minepacu.boothlistmanager.ui.home
import android.util.Log
import android.view.View
import android.widget.Button
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.chaquo.python.PyException
import com.google.android.material.snackbar.Snackbar
import com.minepacu.boothlistmanager.R
import com.minepacu.boothlistmanager.data.model.Result
import com.minepacu.boothlistmanager.tools.PythonCode.PythonClass
import kotlinx.coroutines.launch
class HomeViewModel : ViewModel() {
// Google API Status TextView
private var _text_ServiceConnectionStatus = MutableLiveData<String>().apply {
value = "์๋น์ค ์ํ"
}
var text_ServiceConnectionStatus: LiveData<String> = _text_ServiceConnectionStatus
private var _image_login = MutableLiveData<Int>().apply {
value = 0
}
var image_login: LiveData<Int> = _image_login
// =============================================================================================
// SheetTitle
private var _text_sheetTitle = MutableLiveData<String>().apply {
value = ""
}
var text_sheetTitle: LiveData<String> = _text_sheetTitle
private var _image_loadedsheetInfo = MutableLiveData<Int>().apply {
value = 0
}
var image_loadedsheetInfo: LiveData<Int> = _image_loadedsheetInfo
// =============================================================================================
private var _text_worksheetTitle = MutableLiveData<String>().apply {
value = ""
}
var text_worksheetTitle: LiveData<String> = _text_worksheetTitle
private var _image_loadedworksheetInfo = MutableLiveData<Int>().apply {
value = 0
}
var image_loadedworksheetInfo: LiveData<Int> = _image_loadedworksheetInfo
// =============================================================================================
private var _text_preorder_info_sheetTitle = MutableLiveData<String>().apply {
value = ""
}
var text_preorder_info_sheetTitle: LiveData<String> = _text_preorder_info_sheetTitle
private var _text_mail_order_sheetTitle = MutableLiveData<String>().apply {
value = ""
}
var text_mail_order_sheetTitle: LiveData<String> = _text_mail_order_sheetTitle
private var _text_grasping_demand_sheetTitle = MutableLiveData<String>().apply {
value = ""
}
var text_grasping_demand_sheetTitle: LiveData<String> = _text_grasping_demand_sheetTitle
private var _image_preorder_info_sheet = MutableLiveData<Int>().apply {
value = 0
}
var image_preorder_info_sheet: LiveData<Int> = _image_preorder_info_sheet
private var _image_mail_order_sheet = MutableLiveData<Int>().apply() {
value = 0
}
var image_mail_order_sheet: LiveData<Int> = _image_mail_order_sheet
private var _image_grasping_demand_sheet = MutableLiveData<Int>().apply {
value = 0
}
var image_grasping_demand_sheet: LiveData<Int> = _image_grasping_demand_sheet
var isLoginToGoogleAPI = false
var isLoadedSheetId = false
/**
* ๊ตฌ๊ธ API์ ๋ก๊ทธ์ธํฉ๋๋ค.
*
* API์ ๋ก๊ทธ์ธ ์ฌ๋ถ์ ๋ฐ๋ผ ์ผ๋ถ ๋ฒํผ๋ค์ ํ์ฑํํ๊ฑฐ๋ ๋นํ์ฑํํฉ๋๋ค.
*
* @param view SnackBar๋ฅผ ํ์ํ View
* @param buttonReloadSheetInfo ํ์ฑํ ๋๋ ๋นํ์ฑํํ ์ํธ ์ ๋ณด ๋ค์ ๋ก๋ ๋ฒํผ
* @param buttonReloadWorkSheetInfo ํ์ฑํ ๋๋ ๋นํ์ฑํํ ์ํฌ ์ํธ ์ ๋ณด ๋ค์ ๋ก๋ ๋ฒํผ
*/
fun loginToGoogleAPI(view : View, buttonReloadSheetInfo: Button, buttonReloadWorkSheetInfo: Button) {
viewModelScope.launch {
val result = try {
PythonClass.loginToGoogleAPI()
} catch (e : PyException) {
Result.Error(Exception(e.message))
}
when (result) {
is Result.Success<Boolean> -> {
_text_ServiceConnectionStatus.value = "๋ก๊ทธ์ธ ๋จ"
isLoginToGoogleAPI = true
_image_login.value = R.drawable.check_circle_24dp
buttonReloadSheetInfo.isEnabled = true
buttonReloadWorkSheetInfo.isEnabled = true
}
else -> {
_text_ServiceConnectionStatus.value = "๋ก๊ทธ์ธ ๋ถ๊ฐ"
_image_login.value = R.drawable.cancel_24dp
Snackbar.make(view, "๊ตฌ๊ธ API์ ๋ก๊ทธ์ธํ ์ ์์ต๋๋ค.", Snackbar.LENGTH_LONG)
.show()
}
}
}
}
/**
* ์ํธ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
*
* ์ดํ์ ์๋์ผ๋ก ํ์ํ ์ํฌ ์ํธ๋ค์ ์ ๋ณด๋ค์ ๊ฐ์ด ๊ฐ์ ธ์ต๋๋ค.
*
* @param view SnackBar๋ฅผ ํ์ํ View
* @param sheetId ์ํฌ ์ํธ๋ฅผ ๊ฐ์ ธ์ฌ ์ํธ์ ID
* @param preorder_SheetNumber ๊ฐ์ ธ์ฌ ์ ์
๊ธ ์ํธ์ ์ธ๋ฑ์ค
* @param mail_order_SheetNumber ๊ฐ์ ธ์ฌ ํตํ ์ํธ์ ์ธ๋ฑ์ค
* @param grasping_Demand_SheetNumber ๊ฐ์ ธ์ฌ ์์์กฐ์ฌ ์ํธ์ ์ธ๋ฑ์ค
*/
fun getSheet(view : View, sheetId: String, preorder_SheetNumber: Int, mail_order_SheetNumber: Int, grasping_Demand_SheetNumber: Int) {
viewModelScope.launch {
val result2 = try {
PythonClass.getSheet(sheetId)
} catch (e : PyException) {
Result.Error(Exception(e.message))
}
when (result2) {
is Result.Success<Boolean> -> {
isLoadedSheetId = true
_text_sheetTitle.value =
PythonClass.getVariable("sheet")?.get("title").toString()
_image_loadedsheetInfo.value = R.drawable.check_circle_24dp
}
else -> {
_text_sheetTitle.value = "์ํธ ์์"
_image_loadedsheetInfo.value = R.drawable.cancel_24dp
Snackbar.make(view, "์ํธ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค", Snackbar.LENGTH_LONG)
.show()
}
}
getWorksheetTitle(view, sheetId, preorder_SheetNumber, mail_order_SheetNumber, grasping_Demand_SheetNumber, isLoadedSheetId)
}
}
/**
* ์ง์ ํ ์ํฌ ์ํธ์ ํ์ดํ์ ๊ฐ์ ธ์ TextView UI์ ๋ฐ์ํฉ๋๋ค.
*
* ๋ชจ๋ ์ธ๋ฑ์ค ๊ฐ์ 0๋ถํฐ ์์ํฉ๋๋ค.
*
* @param view SnackBar๋ฅผ ํ์ํ View
* @param sheetId ์ํฌ ์ํธ๋ฅผ ๊ฐ์ ธ์ฌ ์ํธ์ ID
* @param preorder_SheetNumber ๊ฐ์ ธ์ฌ ์ ์
๊ธ ์ํธ์ ์ธ๋ฑ์ค
* @param mail_order_SheetNumber ๊ฐ์ ธ์ฌ ํตํ ์ํธ์ ์ธ๋ฑ์ค
* @param grasping_Demand_SheetNumber ๊ฐ์ ธ์ฌ ์์์กฐ์ฌ ์ํธ์ ์ธ๋ฑ์ค
* @param isLoadedSheetInfo ๋ฏธ๋ฆฌ ์ํธ๊ฐ ๋ก๋๋์ด ์๋์ง ์ฌ๋ถ
*/
fun getWorksheetTitle(view: View, sheetId: String, preorder_SheetNumber: Int, mail_order_SheetNumber: Int, grasping_Demand_SheetNumber: Int, isLoadedSheetInfo: Boolean) {
viewModelScope.launch {
if (isLoadedSheetInfo == false) {
_text_worksheetTitle.value = "์์"
_text_preorder_info_sheetTitle.value = "์์"
_text_mail_order_sheetTitle.value = "์์"
_text_grasping_demand_sheetTitle.value = "์์"
_image_loadedworksheetInfo.value = R.drawable.cancel_24dp
_image_preorder_info_sheet.value = R.drawable.cancel_24dp
_image_mail_order_sheet.value = R.drawable.cancel_24dp
_image_grasping_demand_sheet.value = R.drawable.cancel_24dp
Snackbar.make(view, "์ํฌ ์ํธ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค", Snackbar.LENGTH_LONG)
.show()
}
else {
_text_worksheetTitle.value = "๊ณต์ฌ ์ค..."
_image_loadedworksheetInfo.value = R.drawable.cancel_24dp
val result_preorder = try {
PythonClass.getWorkSheet(sheetId, preorder_SheetNumber)
Log.d("Debug", "preorder_SheetNumber : " + preorder_SheetNumber)
Log.d("Debug", "preorder_SheetTitle : " +
PythonClass.getVariable("worksheet")?.get("title").toString())
PythonClass.getVariable("worksheet")?.get("title").toString()
} catch (e: PyException) {
"null"
}
val result_mail_order = try {
PythonClass.getWorkSheet(sheetId, mail_order_SheetNumber)
Log.d("Debug", "mail_order_SheetNumber : " + mail_order_SheetNumber)
Log.d("Debug", "mail_order_SheetTitle : " +
PythonClass.getVariable("worksheet")?.get("title").toString())
PythonClass.getVariable("worksheet")?.get("title").toString()
} catch (e: PyException) {
"null"
}
val result_grasping_demand = try {
PythonClass.getWorkSheet(sheetId, grasping_Demand_SheetNumber)
Log.d("Debug", "grasping_Demand_SheetNumber : " + grasping_Demand_SheetNumber)
Log.d("Debug", "grasping_Demand_SheetTitle : " +
PythonClass.getVariable("worksheet")?.get("title").toString())
PythonClass.getVariable("worksheet")?.get("title").toString()
} catch (e: PyException) {
"null"
}
when {
result_preorder != "null" -> {
_text_preorder_info_sheetTitle.value = "์ ์
๊ธ ์ํธ : " + result_preorder
_image_preorder_info_sheet.value = R.drawable.check_circle_24dp
}
else -> {
_text_preorder_info_sheetTitle.value = "์์"
_image_preorder_info_sheet.value = R.drawable.cancel_24dp
Snackbar.make(view, "์ํฌ ์ํธ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค", Snackbar.LENGTH_LONG)
.show()
}
}
when {
result_mail_order != "null" -> {
_text_mail_order_sheetTitle.value = "ํตํ ์ํธ : " + result_mail_order
_image_mail_order_sheet.value = R.drawable.check_circle_24dp
}
else -> {
_text_mail_order_sheetTitle.value = "์์"
_image_mail_order_sheet.value = R.drawable.cancel_24dp
Snackbar.make(view, "์ํฌ ์ํธ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค", Snackbar.LENGTH_LONG)
.show()
}
}
when {
result_grasping_demand != "null" -> {
_text_grasping_demand_sheetTitle.value = "์์์กฐ์ฌ ์ํธ : " + result_grasping_demand
_image_grasping_demand_sheet.value = R.drawable.check_circle_24dp
}
else -> {
_text_grasping_demand_sheetTitle.value = "์์"
_image_grasping_demand_sheet.value = R.drawable.cancel_24dp
Snackbar.make(view, "์ํฌ ์ํธ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค", Snackbar.LENGTH_LONG)
.show()
}
}
}
}
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/ui/home/HomeViewModel.kt | 1345120992 |
package com.minepacu.boothlistmanager.ui.home
import android.content.SharedPreferences
import android.media.Image
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.preference.PreferenceManager
import com.chaquo.python.Python
import com.chaquo.python.android.AndroidPlatform
import com.minepacu.boothlistmanager.R
import com.minepacu.boothlistmanager.databinding.FragmentHomeBinding
import com.minepacu.boothlistmanager.tools.PythonCode.PythonClass
import org.w3c.dom.Text
class HomeFragment : Fragment() {
private var _binding: FragmentHomeBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
lateinit var prefs: SharedPreferences
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val homeViewModel =
ViewModelProvider(this).get(HomeViewModel::class.java)
_binding = FragmentHomeBinding.inflate(inflater, container, false)
val root: View = binding.root
prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
PreferenceManager.setDefaultValues(requireContext(), R.xml.preference, false)
// Google API Service Status
val textView_ServiceConnectionStatus: TextView = binding.textServiceConnectionStatus
homeViewModel.text_ServiceConnectionStatus.observe(viewLifecycleOwner) {
textView_ServiceConnectionStatus.text = it
}
// Google API Login Status Icon
val image_Login: ImageView = binding.imageLogin
homeViewModel.image_login.observe(viewLifecycleOwner) {
image_Login.setImageResource(it)
}
// =======================================================================================
// Connected Sheet Title
val textView_SheetTitle: TextView = binding.sheetTitle
homeViewModel.text_sheetTitle.observe(viewLifecycleOwner) {
textView_SheetTitle.text = it
}
val image_loadedsheetInfo: ImageView = binding.imageLoadedsheetInfo
homeViewModel.image_loadedsheetInfo.observe(viewLifecycleOwner) {
image_loadedsheetInfo.setImageResource(it)
}
// =======================================================================================
// WorkSheet_TItle
val textView_WorkSheetTitle: TextView = binding.worksheetTitle
homeViewModel.text_worksheetTitle.observe(viewLifecycleOwner) {
textView_WorkSheetTitle.text = it
}
val image_loadedworkSheetInfo: ImageView = binding.imageLoadedworksheetInfo
homeViewModel.image_loadedworksheetInfo.observe(viewLifecycleOwner) {
image_loadedworkSheetInfo.setImageResource(it)
}
// ======================================================================================
val textView_preoder_info_sheetTitle: TextView = binding.preorderInfoSheetTitle
homeViewModel.text_preorder_info_sheetTitle.observe(viewLifecycleOwner) {
textView_preoder_info_sheetTitle.text = it
}
val textView_mail_order_sheetTitle: TextView = binding.mailOrderSheetTitle
homeViewModel.text_mail_order_sheetTitle.observe(viewLifecycleOwner) {
textView_mail_order_sheetTitle.text = it
}
val textView_grasping_demand_sheetTitle: TextView = binding.graspingDemandSheetTitle
homeViewModel.text_grasping_demand_sheetTitle.observe(viewLifecycleOwner) {
textView_grasping_demand_sheetTitle.text = it
}
val image_preorder_info_sheet: ImageView = binding.imagePreorderInfoSheet
homeViewModel.image_preorder_info_sheet.observe(viewLifecycleOwner) {
image_preorder_info_sheet.setImageResource(it)
}
val image_mail_order_sheet: ImageView = binding.imageMailOrderSheet
homeViewModel.image_mail_order_sheet.observe(viewLifecycleOwner) {
image_mail_order_sheet.setImageResource(it)
}
val image_grasping_demand_sheet: ImageView = binding.imageGraspingDemandSheet
homeViewModel.image_grasping_demand_sheet.observe(viewLifecycleOwner) {
image_grasping_demand_sheet.setImageResource(it)
}
// ========================================================================================
if (!Python.isStarted()) {
getContext()?.let { AndroidPlatform(it) }?.let { Python.start(it) }
}
val sheetId = prefs.getString("sheetId", "")
PythonClass.setVariable("sheetId", sheetId)
val sheetStartIndex = prefs.getString("sheetStartIndex", "")
PythonClass.setVariable("sheetStartIndex", sheetStartIndex?.toInt())
val mapSheetIndex = prefs.getString("booth_map_sheet_Index", "")
PythonClass.setVariable("MapSheetNumber", mapSheetIndex?.toInt())
if (homeViewModel.isLoginToGoogleAPI == false) {
binding.buttonReloadsheetInfo.isEnabled = false
homeViewModel.loginToGoogleAPI(root, binding.buttonReloadsheetInfo, binding.buttonReloadworksheetInfo)
}
if (homeViewModel.isLoadedSheetId == false) {
binding.buttonReloadworksheetInfo.isEnabled = false
prefs.getString("sheetId", "")?.let {
homeViewModel.getSheet(root,
it, prefs.getString("sheetNumber", "")!!.toInt(), prefs.getString("mail_order_sheet_Index", "")!!.toInt(), prefs.getString("grasping_demand_sheet_Index", "")!!.toInt())
}
}
binding.buttonReloadsheetInfo.setOnClickListener {
textView_SheetTitle.text = "๋ก๋ ์ค....."
textView_WorkSheetTitle.text = "๋ก๋ ์ค....."
homeViewModel.isLoadedSheetId = false
prefs.getString("sheetId", "")?.let {
homeViewModel.getSheet(root,
it, prefs.getString("sheetNumber", "")!!.toInt(), prefs.getString("mail_order_sheet_Index", "")!!.toInt(), prefs.getString("grasping_demand_sheet_Index", "")!!.toInt())
}
}
binding.buttonReloadworksheetInfo.setOnClickListener {
textView_SheetTitle.text = "๋ก๋ ์ค....."
textView_WorkSheetTitle.text = "๋ก๋ ์ค....."
homeViewModel.isLoadedSheetId = false
prefs.getString("sheetId", "")?.let {
homeViewModel.getSheet(
root,
it, prefs.getString("sheetNumber", "")!!.toInt(), prefs.getString("mail_order_sheet_Index", "")!!.toInt(), prefs.getString("grasping_demand_sheet_Index", "")!!.toInt())
}
}
return root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/ui/home/HomeFragment.kt | 2116690305 |
package com.minepacu.boothlistmanager.ui.Booth
import android.content.SharedPreferences
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.AutoCompleteTextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.preference.PreferenceManager
import com.chaquo.python.PyException
import com.chaquo.python.Python
import com.google.android.material.button.MaterialButtonToggleGroup
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.timepicker.MaterialTimePicker
import com.google.android.material.timepicker.TimeFormat
import com.minepacu.boothlistmanager.R
import com.minepacu.boothlistmanager.data.model.BoothInfo
import com.minepacu.boothlistmanager.databinding.FragmentAddboothBinding
import com.minepacu.boothlistmanager.tools.PythonCode.PythonClass
import com.minepacu.boothlistmanager.ui.ProgressingPage.ProgressPage
import kotlinx.coroutines.Job
import java.text.SimpleDateFormat
import java.util.Locale
class AddBoothFragment : Fragment() {
private var _binding: FragmentAddboothBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val addboothViewModel =
ViewModelProvider(this).get(AddBoothViewModel::class.java)
_binding = FragmentAddboothBinding.inflate(inflater, container, false)
val root: View = binding.root
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
val addboothButton = binding.filledAddBoothButton
val emptyTextButton = binding.EmptyTextFieldButton
val customProgressPage = this.context?.let { ProgressPage(it) }
customProgressPage?.window?.setBackgroundDrawable(
ColorDrawable(android.graphics.Color.TRANSPARENT))
emptyTextButton.setOnClickListener {
binding.editBoothNumber.editText?.setText("")
binding.editBoothName.editText?.setText("")
binding.editGenre.editText?.setText("")
binding.editInfoLabel.editText?.setText("")
binding.editInfoLabel.editText?.setText("")
binding.editPreorderDateLayout.editText?.setText("")
binding.editPreorderClockLayout.editText?.setText("")
binding.editPreOrderLabel.editText?.setText("")
binding.editPreOrderLink.editText?.setText("")
}
addboothButton.setOnClickListener{
val boothnumber = binding.editBoothNumber.editText?.text.toString()
val boothname = binding.editBoothName.editText?.text.toString()
val genre = binding.editGenre.editText?.text.toString()
val yoil = binding.YoilGroup.checkedRadioButtonId
val infolabel = binding.editInfoLabel.editText?.text.toString()
val infolink = binding.editInfoLink.editText?.text.toString()
val preorder_label = binding.editPreOrderLabel.editText?.text.toString()
val preorder_link = binding.editPreOrderLink.editText?.text.toString()
var new_yoil = ""
when {
yoil == binding.FesInSaturday.id -> new_yoil = "ํ "
yoil == binding.FesInSunday.id -> new_yoil = "์ผ"
yoil == binding.FesInboth.id -> new_yoil = "ํ /์ผ"
yoil == binding.FesInUnknown.id -> new_yoil = "?"
}
val preorder_date = when {
binding.editPreOrderClock.text.toString() != "" -> binding.editPreOrderDate.text.toString() + "//" + binding.editPreOrderClock.text.toString()
else -> binding.editPreOrderDate.text.toString()
}
if (genre.contains("//") == true) {
val tempstr = genre.split("//")
PythonClass.setVariable("dateline_In_aRow", tempstr.count())
} else {
if (binding.editPreOrderClock.text.toString() != "") {
PythonClass.setVariable("dateline_In_aRow", 2)
} else {
PythonClass.setVariable("dateline_In_aRow", 1)
}
}
val boothInfo = BoothInfo(boothnumber, boothname, genre, new_yoil,
infolabel, infolink,
preorder_date, preorder_label, preorder_link)
Log.d("Debug", "BoothInfo : " + boothInfo.toString())
customProgressPage?.show()
changeSheetNumber(it, prefs, binding.selectionSheet)
PythonClass.setVariable("sheetId", prefs.getString("sheetId", ""))
addboothViewModel.addBoothInfoToSheet(root, customProgressPage, boothInfo)
}
binding.addPreorderdateButton.setOnClickListener {
val datepicker = MaterialDatePicker.Builder.datePicker()
.setSelection(MaterialDatePicker.todayInUtcMilliseconds())
.setTitleText("๋ง๊ฐ ์ผ์ ์ ํ")
.build()
datepicker.addOnPositiveButtonClickListener {
val sdf = SimpleDateFormat("M/d(EEE)", Locale.KOREA)
val date = sdf.format(it)
binding.editPreOrderDate.setText(date)
}
datepicker.show(parentFragmentManager, "Tag")
}
binding.addPreorderclockButton.setOnClickListener {
val timepicker = MaterialTimePicker.Builder().setTimeFormat(TimeFormat.CLOCK_24H)
.setInputMode(MaterialTimePicker.INPUT_MODE_CLOCK)
.setHour(12).setMinute(0)
.setTitleText("๋ง๊ฐ ์๊ฐ ์ ํ")
.build()
timepicker.addOnPositiveButtonClickListener {
if (timepicker.minute != 0) {
binding.editPreOrderClock.setText(timepicker.hour.toString() + "์ " + timepicker.minute.toString() + "๋ถ")
} else {
binding.editPreOrderClock.setText(timepicker.hour.toString() + "์")
}
}
timepicker.show(parentFragmentManager, "Tag")
}
binding.selectionSheet.addOnButtonCheckedListener { buttonToggleGroup, checkedId, isChecked ->
changeSheetNumber(view, prefs, buttonToggleGroup)
}
binding.switchDisableAutoLocation.setOnCheckedChangeListener { buttonView, isChekced ->
PythonClass.setVariable("isIgnoreRecommandLocation", isChekced)
}
textWatcher()
//enterTestBooth()
return root
}
/**
* UI [MaterialButtonToggleGroup]์์ ์ ํ๋ ๋ฒํผ์ ๋ฐ๋ผ
*
* ๋ถ์ค ์ ๋ณด๋ฅผ ๋ฑ๋กํ ์ํฌ ์ํธ๋ฅผ ํ์ด์ฌ ๋ชจ๋ [PythonClass.boothListManagementModule]์ ์ค์ ํฉ๋๋ค.
*
* ๋งค๊ฐ ๋ณ์ [buttonToggleGroup]์ด null์ด๋ฉด ์ํฌ ์ํธ๊ฐ ์ค์ ๋์ง ์์ต๋๋ค.
*
* @param view ์ค๋ฅ๊ฐ ์๊ฒผ์ ๋, [Snackbar]๋ฅผ ์ถ๋ ฅํ [View]
* @param prefs ์ฑ์ ์ค์ ๊ฐ์ ์ ์ฅ ์ค์ธ [SharedPreferences] ๊ฐ์ฒด
* @param buttonToggleGroup ์ ์
๊ธ, ํตํ, ์์์กฐ์ฌ ์ํธ ์ค ํ๋๋ฅผ ์ ํํ ์ ์๋ [MaterialButtonToggleGroup] UI ์์
*/
private fun changeSheetNumber(view: View?, prefs: SharedPreferences, buttonToggleGroup: MaterialButtonToggleGroup?) {
if (buttonToggleGroup == null) {
return
}
if (buttonToggleGroup.checkedButtonId == R.id.preorderButton) {
try {
val sheetIndex_Set = prefs.getString("sheetNumber", "")
val updatesheetIndex_Set = prefs.getString("updateSheetNumber", "")
PythonClass.setVariable("sheetNumber", sheetIndex_Set?.toInt())
PythonClass.setVariable(
"UpdateLogSheetNumber",
updatesheetIndex_Set?.toInt()
)
Log.d("Debug", "sheetNumber is updated to " + sheetIndex_Set)
} catch (e: PyException) {
view?.let {
Snackbar.make(
it,
"Error : " + e.message,
Snackbar.LENGTH_LONG
)
}
}
} else if (buttonToggleGroup.checkedButtonId == R.id.maIlorderButton) {
try {
val sheetIndex_Set = prefs.getString("mail_order_sheet_Index", "")
val updatesheetIndex_Set =
prefs.getString("update_mail_order_sheetIndex", "")
PythonClass.setVariable("sheetNumber", sheetIndex_Set?.toInt())
PythonClass.setVariable(
"UpdateLogSheetNumber",
updatesheetIndex_Set?.toInt()
)
Log.d("Debug", "sheetNumber is updated to " + sheetIndex_Set)
} catch (e: PyException) {
view?.let {
Snackbar.make(
it,
"Error : " + e.message,
Snackbar.LENGTH_LONG
)
}
}
} else if (buttonToggleGroup.checkedButtonId == R.id.graspingdemandButton) {
try {
val sheetIndex_Set = prefs.getString("grasping_demand_sheet_Index", "")
val updatesheetIndex_Set =
prefs.getString("update_grasping_demand_sheetIndex", "")
PythonClass.setVariable("sheetNumber", sheetIndex_Set?.toInt())
PythonClass.setVariable(
"UpdateLogSheetNumber",
updatesheetIndex_Set?.toInt()
)
Log.d("Debug", "sheetNumber is updated to " + sheetIndex_Set)
} catch (e: PyException) {
view?.let {
Snackbar.make(
it,
"Error : " + e.message,
Snackbar.LENGTH_LONG
)
}
}
}
}
fun textWatcher() {
binding.editTextBoothName.addTextChangedListener (object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
override fun afterTextChanged(s: Editable?) {
if (binding.editTextBoothName.text!!.isEmpty()) {
binding.editBoothName.error = "๋ถ์ค ์ด๋ฆ์ ์
๋ ฅํด์ฃผ์ธ์"
} else {
binding.editBoothName.error = null
}
}
})
binding.editTextGenre.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
override fun afterTextChanged(s: Editable?) {
if (binding.editTextGenre.text!!.isEmpty()) {
binding.editGenre.error = "๋ถ์ค๊ฐ ์ทจ๊ธํ๋ ์ฅ๋ฅด๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
} else {
binding.editGenre.error = null
}
}
})
}
fun enterTestBooth() {
binding.preorderButton.isPressed = false
binding.editTextBoothNumber.setText("")
binding.editTextBoothName.setText("")
binding.editTextGenre.setText(")")
binding.FesInSaturday.isChecked = false
binding.editPreOrderDate.setText("")
binding.editTextPreOrderLabel.setText("")
binding.editTextPreOrderLink.setText("")
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/ui/Booth/AddBoothFragment.kt | 290536477 |
package com.minepacu.boothlistmanager.ui.Booth
import android.view.View
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.android.material.snackbar.Snackbar
import com.minepacu.boothlistmanager.data.model.BoothInfo
import com.minepacu.boothlistmanager.tools.PythonCode.PythonClass
import com.minepacu.boothlistmanager.data.model.Result
import com.minepacu.boothlistmanager.ui.ProgressingPage.ProgressPage
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
class AddBoothViewModel : ViewModel() {
/**
* ์ง์ ํ ์ํฌ ์ํธ์ ๋ถ์ค ์ ๋ณด๋ฅผ ์ถ๊ฐํฉ๋๋ค.
*
* ์ง์ ํ ์ํฌ ์ํธ๋ [PythonClass.boothListManagementModule]์ ์๋ sheetNumber์ ์ํด ๊ฒฐ์ ๋ฉ๋๋ค.
*
* @param view ์ค๋ฅ๊ฐ ๋ฌ์ ๋, ์ค๋ฅ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํ [Snackbar]๋ฅผ ์ฌ์ฉํ [View]
* @param progressPage [android.app.Dialog.show] ํจ์๋ฅผ ์ด๋ฏธ ์ฌ์ฉํ [ProgressPage] ๊ฐ์ฒด
* @param boothInfo ์ถ๊ฐํ ๋ถ์ค์ ์ ๋ณด๊ฐ ์ ์ฅ๋ [BoothInfo] ๊ฐ์ฒด
*
* @return ๋ถ์ค ์ถ๊ฐ ์์
์ ์ํํ๋ [Job] ๊ฐ์ฒด
*/
fun addBoothInfoToSheet(view : View, progressPage: ProgressPage?, boothInfo : BoothInfo): Job {
return viewModelScope.launch {
val result = async { PythonClass.addBoothInfoToSheet(boothInfo) }
val result_ = result.await()
when (result_) {
is Result.Success<Boolean> -> {
Snackbar.make(view, "๋ถ์ค ๋ชฉ๋ก ์ํธ์ ํด๋น ๋ถ์ค ์ ๋ณด๊ฐ ์ถ๊ฐ๋์์ต๋๋ค.",
Snackbar.LENGTH_LONG)
.show()
progressPage?.hide()
}
else -> {
Snackbar.make(
view, "๋ถ์ค ๋ชฉ๋ก ์ํธ์ ๋ถ์ค ์ ๋ณด๊ฐ ์ถ๊ฐ๋์ง ๋ชปํ์ต๋๋ค.",
Snackbar.LENGTH_LONG
)
.show()
progressPage?.hide()
}
}
}
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/ui/Booth/AddBoothViewModel.kt | 2495467078 |
package com.minepacu.boothlistmanager.ui.HyperLinkGenerator
import android.content.SharedPreferences
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.AutoCompleteTextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.preference.PreferenceManager
import com.chaquo.python.PyException
import com.google.android.material.button.MaterialButtonToggleGroup
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.timepicker.MaterialTimePicker
import com.google.android.material.timepicker.TimeFormat
import com.minepacu.boothlistmanager.R
import com.minepacu.boothlistmanager.databinding.FragmentHyperlinkgeneratorBinding
import com.minepacu.boothlistmanager.tools.PythonCode.PythonClass
import com.minepacu.boothlistmanager.ui.ProgressingPage.ProgressPage
import java.text.SimpleDateFormat
import java.util.Locale
class HyperLinkGeneratorFragment : Fragment() {
private var _binding: FragmentHyperlinkgeneratorBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val hyperLinkGeneratorViewModel =
ViewModelProvider(this).get(HyperLinkGeneratorViewModel::class.java)
_binding = FragmentHyperlinkgeneratorBinding.inflate(inflater, container, false)
val root: View = binding.root
val customProgressPage = this.context?.let { ProgressPage(it) }
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
binding.filledCopyToClipBoardButton.setOnClickListener {
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
if ((binding.editLinkSheetnumber.text.toString() != "") &&
(binding.editLinkBoothCell.text.toString() != "")) {
val sheetId = prefs.getString("sheetId", "")
val sheetNumber = binding.editLinkSheetnumber.text.toString().toInt()
//customProgressPage?.show()
val job = hyperLinkGeneratorViewModel.getGid(root, requireContext(),
sheetId!!, sheetNumber, binding.editLinkBoothCell.text.toString(), binding.editLinklabel.text.toString())
} else if (binding.editLinklabel.text.toString() != "") {
customProgressPage?.show()
hyperLinkGeneratorViewModel.getHyperLinkWithTextJoin(it, requireContext(), customProgressPage, binding.editLink.text.toString(), binding.editLinklabel.text.toString())
} else {
Snackbar.make(root, "ํ์ดํผ๋งํฌ ํจ์๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค. [์ํธ ๋๋ฒ, ์ํธ a1 ๊ฐ] ๋๋ ๋งํฌ ๋ผ๋ฒจ์ด ๋น ์นธ์ด ์๋์ฌ์ผ ํฉ๋๋ค.", Snackbar.LENGTH_SHORT)
.show()
}
}
binding.EmptyTextFieldButton.setOnClickListener {
binding.editLinkSheetnumber.setText("")
binding.editLinkBoothCell.setText("")
binding.editLinklabel.setText("")
binding.editLink.setText("")
}
binding.filledAddUpdateLogButton.setOnClickListener {
customProgressPage?.window?.setBackgroundDrawable(
ColorDrawable(Color.TRANSPARENT)
)
customProgressPage?.show()
changeSheetNumber(it, prefs, binding.selectionSheet)
val mode = when (binding.typeinpredoerorInfo.checkedButtonId) {
R.id.info_Button_InSelection -> 1
else -> 0
}
hyperLinkGeneratorViewModel.addUpdateLog(
root, customProgressPage,
binding.editBoothnameUpdate.text.toString(), binding.editLinkUpdate.text.toString(), binding.editOffsetUpdate.text.toString().toInt(), mode)
}
binding.selectionSheet.addOnButtonCheckedListener { buttonToggleGroup, checkedId, isChecked ->
changeSheetNumber(view, prefs, buttonToggleGroup)
when (buttonToggleGroup.checkedButtonId) {
R.id.preorderButton -> binding.typeinpredoerorInfo.isEnabled = true
else -> binding.typeinpredoerorInfo.isEnabled = false
}
}
binding.addDateButton.setOnClickListener {
val datepicker = MaterialDatePicker.Builder.datePicker()
.setSelection(MaterialDatePicker.todayInUtcMilliseconds())
.setTitleText("๋ง๊ฐ ์ผ์ ์ ํ").build()
datepicker.addOnPositiveButtonClickListener {
val sdf = SimpleDateFormat("M/d(EEE)", Locale.KOREA)
val date = sdf.format(it)
binding.editDate.setText(date)
}
datepicker.show(getParentFragmentManager(), "tag")
}
binding.addClockButton.setOnClickListener {
val timepicker = MaterialTimePicker.Builder().setTimeFormat(TimeFormat.CLOCK_24H)
.setInputMode(MaterialTimePicker.INPUT_MODE_CLOCK)
.setHour(12).setMinute(0)
.setTitleText("๋ง๊ฐ ์๊ฐ ์ ํ").build()
timepicker.addOnPositiveButtonClickListener {
if (timepicker.minute != 0) {
binding.editClock.setText(timepicker.hour.toString() + "์ " + timepicker.minute + "๋ถ")
} else {
binding.editClock.setText(timepicker.hour.toString() + "์")
}
}
timepicker.show(parentFragmentManager, "tag")
}
binding.CopyToClipBoardButtonDate.setOnClickListener {
var copystring = ""
if (binding.editClock.text.toString() != "") {
copystring = "=TEXTJOIN(CHAR(10), 0, \"" + binding.editDate.text.toString() + "\", \"" + binding.editClock.text.toString() + "\")"
} else {
copystring = binding.editDate.text.toString()
}
hyperLinkGeneratorViewModel.textCopyThenPost(requireContext(), copystring)
}
binding.EmptyTextFieldButtonDate.setOnClickListener {
binding.editDate.setText("")
binding.editClock.setText("")
}
binding.selectionSheetMovingData.addOnButtonCheckedListener { buttonToggleGroup, checkedId, isChecked ->
changeSheetNumber(view, prefs, buttonToggleGroup)
}
binding.moveBoothDataButton.setOnClickListener {
val originRowIndex = binding.editOriginrownumber.text.toString().toInt()
val moveRowIndex = binding.editMovedrownumber.text.toString().toInt()
customProgressPage?.window?.setBackgroundDrawable(
ColorDrawable(Color.TRANSPARENT)
)
customProgressPage?.show()
hyperLinkGeneratorViewModel.moveBoothData(it, customProgressPage, originRowIndex, moveRowIndex)
}
binding.EmptyTextFieldButtonMoveinfotool.setOnClickListener {
binding.editOriginrownumber.setText("")
binding.editMovedrownumber.setText("")
}
binding.selectionSheetPutBoothNumber.addOnButtonCheckedListener { buttonToggleGroup, checkedId, isChecked ->
changeSheetNumber(view, prefs, buttonToggleGroup)
}
binding.putBoothNumberButton.setOnClickListener {
val boothname_put = binding.editBoothnameToputBoothNumber.text.toString()
val boothNumber_put = binding.editBoothnumberToputBoothNumber.text.toString()
customProgressPage?.window?.setBackgroundDrawable(
ColorDrawable(Color.TRANSPARENT)
)
customProgressPage?.show()
hyperLinkGeneratorViewModel.putBoothNumberToSpecificBooth(it, customProgressPage, boothname_put, boothNumber_put)
}
binding.EmptyTextFieldButtonPutBoothNumber.setOnClickListener {
binding.editBoothnameToputBoothNumber.setText("")
binding.editBoothnumberToputBoothNumber.setText("")
}
textWatcher()
return root
}
/**
* UI [MaterialButtonToggleGroup]์์ ์ ํ๋ ๋ฒํผ์ ๋ฐ๋ผ
*
* ๋ถ์ค ์ ๋ณด๋ฅผ ๋ฑ๋กํ ์ํฌ ์ํธ๋ฅผ ํ์ด์ฌ ๋ชจ๋ [PythonClass.boothListManagementModule]์ ์ค์ ํฉ๋๋ค.
*
* ๋งค๊ฐ ๋ณ์ [buttonToggleGroup]์ด null์ด๋ฉด ์ํฌ ์ํธ๊ฐ ์ค์ ๋์ง ์์ต๋๋ค.
*
* @param view ์ค๋ฅ๊ฐ ์๊ฒผ์ ๋, [Snackbar]๋ฅผ ์ถ๋ ฅํ [View]
* @param prefs ์ฑ์ ์ค์ ๊ฐ์ ์ ์ฅ ์ค์ธ [SharedPreferences] ๊ฐ์ฒด
* @param buttonToggleGroup ์ ์
๊ธ, ํตํ, ์์์กฐ์ฌ ์ํธ ์ค ํ๋๋ฅผ ์ ํํ ์ ์๋ [MaterialButtonToggleGroup] UI ์์
*/
private fun changeSheetNumber(view: View?, prefs: SharedPreferences, buttonToggleGroup: MaterialButtonToggleGroup?) {
if (buttonToggleGroup == null) {
return
}
if (buttonToggleGroup.checkedButtonId == R.id.preorderButton) {
try {
val sheetIndex_Set = prefs.getString("sheetNumber", "")
val updatesheetIndex_Set = prefs.getString("updateSheetNumber", "")
PythonClass.setVariable("sheetNumber", sheetIndex_Set?.toInt())
PythonClass.setVariable(
"UpdateLogSheetNumber",
updatesheetIndex_Set?.toInt()
)
Log.d("Debug", "sheetNumber is updated to " + sheetIndex_Set)
} catch (e: PyException) {
view?.let {
Snackbar.make(
it,
"Error : " + e.message,
Snackbar.LENGTH_LONG
)
}
}
} else if (buttonToggleGroup.checkedButtonId == R.id.maIlorderButton) {
try {
val sheetIndex_Set = prefs.getString("mail_order_sheet_Index", "")
val updatesheetIndex_Set =
prefs.getString("update_mail_order_sheetIndex", "")
PythonClass.setVariable("sheetNumber", sheetIndex_Set?.toInt())
PythonClass.setVariable(
"UpdateLogSheetNumber",
updatesheetIndex_Set?.toInt()
)
Log.d("Debug", "sheetNumber is updated to " + sheetIndex_Set)
} catch (e: PyException) {
view?.let {
Snackbar.make(
it,
"Error : " + e.message,
Snackbar.LENGTH_LONG
)
}
}
} else if (buttonToggleGroup.checkedButtonId == R.id.graspingdemandButton) {
try {
val sheetIndex_Set = prefs.getString("grasping_demand_sheet_Index", "")
val updatesheetIndex_Set =
prefs.getString("update_grasping_demand_sheetIndex", "")
PythonClass.setVariable("sheetNumber", sheetIndex_Set?.toInt())
PythonClass.setVariable(
"UpdateLogSheetNumber",
updatesheetIndex_Set?.toInt()
)
Log.d("Debug", "sheetNumber is updated to " + sheetIndex_Set)
} catch (e: PyException) {
view?.let {
Snackbar.make(
it,
"Error : " + e.message,
Snackbar.LENGTH_LONG
)
}
}
}
}
fun textWatcher() {
binding.editLinklabel.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
override fun afterTextChanged(s: Editable?) {
if (binding.editLinklabel.text!!.isEmpty()) {
binding.filledCopyToClipBoardButton.isEnabled = false
binding.editLinkLabelLayout.error = "์ฐ๊ฒฐํ ๋งํฌ์ ๋ผ๋ฒจ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
} else {
binding.filledCopyToClipBoardButton.isEnabled = true
binding.editLinkLabelLayout.error = null
}
}
})
binding.editBoothnameUpdate.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
override fun afterTextChanged(s: Editable?) {
if (binding.editBoothnameUpdate.text!!.isEmpty()) {
binding.filledAddUpdateLogButton.isEnabled = false
binding.editBoothnameUpdate.error = "์
๋ฐ์ดํธ ๋ก๊ทธ์ ๋ฑ๋กํ ๋ถ์ค ์ด๋ฆ์ ์
๋ ฅํ์ธ์."
} else {
binding.filledAddUpdateLogButton.isEnabled = true
binding.editBoothnameUpdate.error = null
}
}
})
binding.editLinkUpdate.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
override fun afterTextChanged(s: Editable?) {
if (binding.editLinkUpdate.text!!.isEmpty()) {
binding.filledAddUpdateLogButton.isEnabled = false
binding.editLinkUpdate.error = "์
๋ฐ์ดํธ ๋ก๊ทธ์ ๋ฑ๋กํ ๋งํฌ ์ด๋ฆ์ ์
๋ ฅํ์ธ์."
} else {
binding.filledAddUpdateLogButton.isEnabled = true
binding.editLinkUpdate.error = null
}
}
})
binding.editOffsetUpdate.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun afterTextChanged(s: Editable?) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
if (binding.editOffsetUpdate.text!!.isEmpty()) {
binding.filledAddUpdateLogButton.isEnabled = false
binding.editOffsetUpdate.error = "ํ์ดํผ๋งํฌ์ ์ ์ฉํ ์คํ์
๊ฐ์ ์
๋ ฅํ์ธ์."
} else {
binding.filledAddUpdateLogButton.isEnabled = true
binding.editOffsetUpdate.error = null
}
}
})
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/ui/HyperLinkGenerator/HyperLinkGeneratorFragment.kt | 3459361059 |
package com.minepacu.boothlistmanager.ui.HyperLinkGenerator
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Build
import android.view.View
import android.widget.Toast
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelStore
import androidx.lifecycle.viewModelScope
import com.google.android.material.snackbar.Snackbar
import com.minepacu.boothlistmanager.tools.PythonCode.PythonClass
import com.minepacu.boothlistmanager.data.model.Result
import com.minepacu.boothlistmanager.ui.ProgressingPage.ProgressPage
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
class HyperLinkGeneratorViewModel : ViewModel() {
/**
* ํด๋น ์ํฌ์ํธ์ ์์ด๋(Gid) ๊ฐ์ ๊ฐ์ ธ์ต๋๋ค.
*
* Gid ๊ฐ์ ๊ฐ์ ธ์ค์ง ๋ชปํ ๊ฒฝ์ฐ, [Snackbar]์ ์ค๋ฅ ๋ด์ฉ์ด ์ถ๋ ฅ๋ฉ๋๋ค.
* @param view [SnackBar]๋ฅผ ์ถ๋ ฅํ [View]
* @param context [Toast]๋ฅผ ๋์ธ [context]
* @param sheetId ๊ฐ์ ธ์ฌ ์ํธ์ ID
* @param sheetNumber ๊ฐ์ ธ์ฌ ์ํฌ ์ํธ์ ์ธ๋ฑ์ค, ์ด ๊ฐ์ 0๋ถํฐ ์์ํฉ๋๋ค.
* @param boothcell ๋งํฌ๋ก ์ค์ ํ a1Notation ๊ฐ์
๋๋ค.
* @param linkLabel ๋งํฌ์ ๋ผ๋ฒจ์
๋๋ค.
* @return ๋ฐฑ๊ทธ๋ผ์ด๋ ์์
* @see Snackbar
* @see PythonClass.getSheet_WorkSheet
*/
fun getGid(view :View, context: Context, sheetId: String, sheetNumber: Int, boothcell: String, linkLabel: String): Job {
return viewModelScope.launch {
val result = PythonClass.getWorkSheet(sheetId, sheetNumber)
when (result) {
is Result.Success<Boolean> -> {
var gid = PythonClass.now_WorkSheet?.get("id")!!.toInt()
val copiedString = "=HYPERLINK(\"#gid=" + gid.toString() + "&range=" + boothcell + "\", \"" + linkLabel + "\")"
textCopyThenPost(context, copiedString)
Snackbar.make(view, "ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌ๋์์ต๋๋ค.", Snackbar.LENGTH_LONG)
.show()
}
else -> Snackbar.make(view, "ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌ๋์ง ์์์ต๋๋ค.", Snackbar.LENGTH_LONG)
.show()
}
}
}
fun textCopyThenPost(context: Context, textCopied: String) {
val clipboardManager = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboardManager.setPrimaryClip(ClipData.newPlainText("", textCopied))
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
Toast.makeText(context, textCopied + " ๋ณต์ฌ๋จ", Toast.LENGTH_SHORT).show()
}
}
/**
* ์
๋ฐ์ดํธ ๋ก๊ทธ ์ํธ์ ์
๋ฐ์ดํธ ๋ก๊ทธ๋ฅผ ๋ฑ๋กํฉ๋๋ค.
*
* ์ผ๋ถ ๋งค๊ฐ ๋ณ์์ ๊ฐ๋ค๋ก ๋ง๋ค์ด์ง๋ ๋ก๊ทธ์ ํจ์ ์์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
* ```
* =HYPERRINK(CONCATENATE("#gid={๋งํฌํ ์ํฌ ์ํธ์ ID}&range={๋งํฌํ ์ํธ์ a1Notation}",
* SUM(MATCH("{[boothname]", '{๋งํฌํ ์ํฌ ์ํธ์ ํ์ดํ}!C:C, 0), offset), "{๋ก๊ทธ ๋ด์ฉ}")
* ```
* @param view SnackBar๋ฅผ ์ถ๋ ฅํ View
* @param processingRing ๋ก๋ฉ ์ค ํ๋ฉด ์ค๋ธ์ ํธ, ์ด ํจ์๋ฅผ ํธ์ถํ๊ธฐ ์ [android.app.Dialog.show] ํจ์๋ฅผ ์ด๋ฏธ ํธ์ถํ ์ํ์ฌ์ผ ํฉ๋๋ค.
* @param boothname ์
๋ฐ์ดํธ ๋ก๊ทธ์ ๋ฑ๋กํ ๋ถ์ค ์ด๋ฆ
* @param linkName ์
๋ฐ์ดํธ ๋ก๊ทธ์ ๋ฑ๋กํ ๋งํฌ ์ด๋ฆ
* @param offset boothname์ ํด๋นํ๋ ๋ถ์ค๊ฐ ์ด๋ฏธ ๊ฐ์ง๊ณ ์๋ ๋งํฌ์ ์๋ก ํด๋น ๊ฐ๋งํผ ์๋ ํ์ ๋งํฌ ๋์์ผ๋ก ๊ฒ์ํฉ๋๋ค.
* @param mode ํด๋น ์
๋ฐ์ดํธ ๋ก๊ทธ ์ํธ๊ฐ ์ธํฌ Column์ ๋งํฌํด์ผ ํ๋ ๊ฒฝ์ฐ, 1๋ก ์ง์ ํฉ๋๋ค. ๊ทธ ์ด์ธ์๋ 0 ์ ์ฌ์ฉํ์ธ์.
* @see Snackbar
* @see ProgressPage
*/
fun addUpdateLog(view: View, processingRing: ProgressPage?, boothname: String, linkName: String, offset: Int, mode: Int): Job {
return viewModelScope.launch {
val result = PythonClass.addUpdateLog(boothname, linkName, offset, mode)
when (result) {
is Result.Success<Boolean> -> {
processingRing?.hide()
Snackbar.make(view, "์
๋ฐ์ดํธ ๋ก๊ทธ๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์ถ๊ฐ๋์์ต๋๋ค.", Snackbar.LENGTH_LONG)
.show()
}
else -> {
processingRing?.hide()
Snackbar.make(view, "์
๋ฐ์ดํธ ๋ก๊ทธ๊ฐ ์ถ๊ฐ๋์ง ๋ชปํ์ต๋๋ค.", Snackbar.LENGTH_LONG)
.show()
}
}
}
}
/**
* ์ง์ ํ originIndex ์์น์์ moveIndex ์์น๋ก ๋ถ์ค ๋ฐ์ดํฐ๋ฅผ ์ด๋์ํต๋๋ค.
*
* *๋งค๊ฐ ๋ณ์์ ๋ชจ๋ ์ธ๋ฑ์ค๋ ์ด๋ํ๊ธฐ ์ ์ ์ธ๋ฑ์ค ๊ฐ์ ๊ธฐ์ค์ผ๋ก ํฉ๋๋ค.*
*
* @param view ์ค๋ฅ๊ฐ ์๊ฒผ์ ๋, [Snackbar]๋ฅผ ์ถ๋ ฅํ [View] ๊ฐ์ฒด
* @param processingRing ์ด๋ ์ค์ผ ๋, ์ถ๋ ฅํ ๋ก๋ฉ ์ฐฝ ([ProgressPage]) ๊ฐ์ฒด
* @param originIndex ์ด๋ํ๋ ค๋ ๋ถ์ค ๋ฐ์ดํฐ๊ฐ ์๋ ์ธ๋ฑ์ค
* @param moveIndex ์ด๋ํ๋ ค๋ ์์น์ ์ธ๋ฑ์ค
* @return ๋ฐฑ๊ทธ๋ผ์ด๋ ์์
([Job]) ๊ฐ์ฒด
*/
fun moveBoothData(view: View, processingRing: ProgressPage?, originIndex: Int, moveIndex: Int) : Job {
return viewModelScope.launch {
val result = PythonClass.moveBoothData(originIndex, moveIndex)
when (result) {
is Result.Success<Boolean> -> {
processingRing?.hide()
Snackbar.make(view, "๋ถ์ค ์ ๋ณด๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ์ด๋ํ์ต๋๋ค.", Snackbar.LENGTH_LONG)
.show()
}
else -> {
processingRing?.hide()
Snackbar.make(view, "๋ถ์ค ์ ๋ณด๋ฅผ ์ด๋ํ์ง ๋ชปํ์ต๋๋ค.", Snackbar.LENGTH_LONG)
.show()
}
}
}
}
/**
* ๋งค๊ฐ ๋ณ์ [boothname]์ ํด๋นํ๋ ๋ถ์ค ๋ฐ์ดํฐ์ ์ง์ ํ ๋ถ์ค ๋ฒํธ ([boothnumber])๋ฅผ ํ ๋นํฉ๋๋ค.
*
* @param view ํจ์์ ์คํ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๋ [Snackbar]๋ฅผ ์ถ๋ ฅํ [View] ๊ฐ์ฒด
* @param processingRing ํจ์๊ฐ ์คํ๋๋ ๋์, ์ถ๋ ฅํ ๋ก๋ฉ ์ฐฝ ([ProgressPage]) ๊ฐ์ฒด
* @param boothName ๋ถ์ค ๋ฒํธ๋ฅผ ํ ๋นํ ๋ถ์ค์ ์ด๋ฆ
* @param boothNumber ํ ๋นํ ๋ถ์ค ๋ฒํธ, ์ผ๋ฐ์ ์ผ๋ก [๋ถ์ค ์ฝ๋] + [์ซ์] ์กฐํฉ์ด๋ฉฐ, [๋ถ์ค ์ฝ๋]์ ์๋ฌธ์ ์ํ๋ฒณ์ด ํฌํ๋ ๊ฒฝ์ฐ, ์๋์ผ๋ก ๋๋ฌธ์๋ก ๋ณํํฉ๋๋ค.
* @return ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์๋ํ๋ ์ฝ๋ฃจํด ์ ๋ณด๋ฅผ ์ ์ ํ [Job] ๊ฐ์ฒด
*/
fun putBoothNumberToSpecificBooth(view: View, processingRing: ProgressPage?, boothName: String, boothNumber: String) : Job {
return viewModelScope.launch {
val result = PythonClass.putBoothNumbertoSpecificBooth(boothName, boothNumber)
when (result) {
is Result.Success<Boolean> -> {
processingRing?.hide()
Snackbar.make(view, "๋ถ์ค ๋ฒํธ๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ๋ฑ๋กํ์ต๋๋ค.", Snackbar.LENGTH_LONG)
.show()
}
else -> {
processingRing?.hide()
Snackbar.make(view, "๋ถ์ค ๋ฒํธ๋ฅผ ๋ฑ๋กํ์ง ๋ชปํ์ต๋๋ค. : " + result.toString(), Snackbar.LENGTH_LONG)
.show()
}
}
}
}
/**
* ๋งค๊ฐ ๋ณ์ [link]์ [label]๋ฅผ ์ด์ฉํ์ฌ ์คํ๋ ๋์ํธ์ ํ์ดํผ๋งํฌ ํจ์๋ฅผ ์์ฑํฉ๋๋ค.
*
* ๋งค๊ฐ ๋ณ์ [label]์์ ๋ฌธ์ `//`๊ฐ ์๋ ๊ฒฝ์ฐ, *TextJoin* ํจ์๋ฅผ ์ด์ฉํ์ฌ ์ค ๋ฐ๊ฟ์ ํฉ๋๋ค.
*
* @param view ํจ์์ ์คํ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๋ [Snackbar]๋ฅผ ์ถ๋ ฅํ [View] ๊ฐ์ฒด
* @param context ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌํ๋๋ฐ ์ฐ์ด๋ [Context] ๊ฐ์ฒด
* @param processingRing ํจ์๊ฐ ์คํ๋๋ ๋์, ์ถ๋ ฅํ ๋ก๋ฉ ์ฐฝ ([ProgressPage]) ๊ฐ์ฒด
* @param link ํ์ดํผ๋งํฌ ํจ์์ ๋ค์ด๊ฐ๋ ๋งํฌ
* @param label ํ์ดํผ๋งํฌ ํจ์์์ ๋ค์ด๊ฐ๋ ๋ผ๋ฒจ
* @return ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์๋ํ๋ ์ฝ๋ฃจํด ์ ๋ณด๋ฅผ ์ ์ ํ [Job] ๊ฐ์ฒด
*/
fun getHyperLinkWithTextJoin(view: View, context: Context, processingRing: ProgressPage?, link: String, label: String) : Job {
return viewModelScope.launch {
val labelWithTextJoin = PythonClass.getLabelWithTextJoin(label)
var result = ""
when {
labelWithTextJoin != "" && !labelWithTextJoin.contains("null") && !labelWithTextJoin.contains("Error") -> {
result = "=HYPERLINK(\"${link}\", ${labelWithTextJoin})"
textCopyThenPost(context, result)
processingRing?.hide()
Snackbar.make(view, "ํจ์๋ฅผ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌํ์ต๋๋ค.", Snackbar.LENGTH_LONG)
.show()
}
else -> {
processingRing?.hide()
Snackbar.make(view, "ํจ์๋ฅผ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌํ์ง ๋ชป์ต๋๋ค. : ${labelWithTextJoin}" , Snackbar.LENGTH_LONG)
.show()
}
}
}
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/ui/HyperLinkGenerator/HyperLinkGeneratorViewModel.kt | 2803073190 |
package com.minepacu.boothlistmanager.ui.ProgressingPage
import android.app.Dialog
import android.content.Context
import android.view.Window
import com.minepacu.boothlistmanager.R
class ProgressPage(context : Context) : Dialog(context) {
init {
requestWindowFeature(Window.FEATURE_NO_TITLE)
setCancelable(false)
setContentView(R.layout.page_progress)
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/ui/ProgressingPage/ProgressPage.kt | 2518441159 |
package com.minepacu.boothlistmanager.ui.Search
import android.content.Intent
import android.content.SharedPreferences
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chaquo.python.PyException
import com.google.android.material.button.MaterialButtonToggleGroup
import com.google.android.material.snackbar.Snackbar
import com.minepacu.boothlistmanager.R
import com.minepacu.boothlistmanager.boothList.BoothsAdapter
import com.minepacu.boothlistmanager.data.model.BoothInfo
import com.minepacu.boothlistmanager.databinding.FragmentSearchboothBinding
import com.minepacu.boothlistmanager.tools.PythonCode.PythonClass
import com.minepacu.boothlistmanager.ui.ProgressingPage.ProgressPage
const val BOOTHNAME = "boothName"
class SearchBoothFragment : Fragment() {
private var _binding: FragmentSearchboothBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
private val searchBoothViewModel by viewModels<SearchBoothViewModel> {
BoothInfoListViewModelFactory(requireContext())
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentSearchboothBinding.inflate(inflater, container, false)
val root: View = binding.root
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
val customProgressPage = this.context?.let { ProgressPage(it) }
customProgressPage?.window?.setBackgroundDrawable(
ColorDrawable(Color.TRANSPARENT)
)
val boothsAdapter = BoothsAdapter { boothInfo -> adapterOnClick(boothInfo) }
val recyclerView: RecyclerView = binding.recyclerViewSearchResult
recyclerView.adapter = boothsAdapter
recyclerView.layoutManager = LinearLayoutManager(context)
searchBoothViewModel.boothsLiveData.observe(viewLifecycleOwner) {
it?.let {
boothsAdapter.submitList(it as MutableList<BoothInfo>)
}
}
binding.selectionSheetSearch.addOnButtonCheckedListener { buttonToggleGroup, checkedId, isChecked ->
changeSheetNumber(view, prefs, buttonToggleGroup)
}
binding.searchBoothButton.setOnClickListener {
customProgressPage?.show()
when {
binding.selectionSearchType.checkedButtonId == R.id.boothname_search && binding.editTextSearchword.text.toString() != "" ->
searchBoothViewModel.searchBoothInfo(it, customProgressPage, boothname = binding.editTextSearchword.text.toString())
binding.selectionSearchType.checkedButtonId == R.id.boothnumber_search && binding.editTextSearchword.text.toString() != "" ->
searchBoothViewModel.searchBoothInfo(it, customProgressPage, boothnumber = binding.editTextSearchword.text.toString())
binding.selectionSearchType.checkedButtonId == R.id.genre_search && binding.editTextSearchword.text.toString() != "" ->
searchBoothViewModel.searchBoothInfo(it, customProgressPage, boothgenre = binding.editTextSearchword.text.toString())
}
}
return root
}
/**
* UI [MaterialButtonToggleGroup]์์ ์ ํ๋ ๋ฒํผ์ ๋ฐ๋ผ
*
* ๋ถ์ค ์ ๋ณด๋ฅผ ๋ฑ๋กํ ์ํฌ ์ํธ๋ฅผ ํ์ด์ฌ ๋ชจ๋ [PythonClass.boothListManagementModule]์ ์ค์ ํฉ๋๋ค.
*
* ๋งค๊ฐ ๋ณ์ [buttonToggleGroup]์ด null์ด๋ฉด ์ํฌ ์ํธ๊ฐ ์ค์ ๋์ง ์์ต๋๋ค.
*
* @param view ์ค๋ฅ๊ฐ ์๊ฒผ์ ๋, [Snackbar]๋ฅผ ์ถ๋ ฅํ [View]
* @param prefs ์ฑ์ ์ค์ ๊ฐ์ ์ ์ฅ ์ค์ธ [SharedPreferences] ๊ฐ์ฒด
* @param buttonToggleGroup ์ ์
๊ธ, ํตํ, ์์์กฐ์ฌ ์ํธ ์ค ํ๋๋ฅผ ์ ํํ ์ ์๋ [MaterialButtonToggleGroup] UI ์์
*/
private fun changeSheetNumber(view: View?, prefs: SharedPreferences, buttonToggleGroup: MaterialButtonToggleGroup?) {
if (buttonToggleGroup == null) {
return
}
if (buttonToggleGroup.checkedButtonId == R.id.preorderButton_search) {
try {
val sheetIndex_Set = prefs.getString("sheetNumber", "")
val updatesheetIndex_Set = prefs.getString("updateSheetNumber", "")
PythonClass.setVariable("sheetNumber", sheetIndex_Set?.toInt())
PythonClass.setVariable(
"UpdateLogSheetNumber",
updatesheetIndex_Set?.toInt()
)
Log.d("Debug", "sheetNumber is updated to " + sheetIndex_Set)
} catch (e: PyException) {
view?.let {
Snackbar.make(
it,
"Error : " + e.message,
Snackbar.LENGTH_LONG
)
}
}
} else if (buttonToggleGroup.checkedButtonId == R.id.maIlorderButton_search) {
try {
val sheetIndex_Set = prefs.getString("mail_order_sheet_Index", "")
val updatesheetIndex_Set =
prefs.getString("update_mail_order_sheetIndex", "")
PythonClass.setVariable("sheetNumber", sheetIndex_Set?.toInt())
PythonClass.setVariable(
"UpdateLogSheetNumber",
updatesheetIndex_Set?.toInt()
)
Log.d("Debug", "sheetNumber is updated to " + sheetIndex_Set)
} catch (e: PyException) {
view?.let {
Snackbar.make(
it,
"Error : " + e.message,
Snackbar.LENGTH_LONG
)
}
}
} else if (buttonToggleGroup.checkedButtonId == R.id.graspingdemandButton_search) {
try {
val sheetIndex_Set = prefs.getString("grasping_demand_sheet_Index", "")
val updatesheetIndex_Set =
prefs.getString("update_grasping_demand_sheetIndex", "")
PythonClass.setVariable("sheetNumber", sheetIndex_Set?.toInt())
PythonClass.setVariable(
"UpdateLogSheetNumber",
updatesheetIndex_Set?.toInt()
)
Log.d("Debug", "sheetNumber is updated to " + sheetIndex_Set)
} catch (e: PyException) {
view?.let {
Snackbar.make(
it,
"Error : " + e.message,
Snackbar.LENGTH_LONG
)
}
}
}
}
private fun adapterOnClick(boothInfo: BoothInfo) {
val intent = Intent(context, SearchBoothFragment::class.java)
intent.putExtra(BOOTHNAME, boothInfo.boothname)
startActivity(intent)
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/ui/Search/SearchBoothFragment.kt | 795359209 |
package com.minepacu.boothlistmanager.ui.Search
import android.content.Context
import android.view.View
import androidx.compose.runtime.internal.illegalDecoyCallException
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.google.android.material.snackbar.Snackbar
import com.minepacu.boothlistmanager.data.DataSource
import com.minepacu.boothlistmanager.data.model.BoothInfo
import com.minepacu.boothlistmanager.tools.PythonCode.PythonClass
import com.minepacu.boothlistmanager.ui.ProgressingPage.ProgressPage
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
class SearchBoothViewModel(val dataSource: DataSource) : ViewModel() {
/*
private val _text = MutableLiveData<String>().apply {
value = "๊ฐ๋ฐ ์ค....."
}
val text: LiveData<String> = _text
*/
val boothsLiveData = dataSource.getBoothInfoList()
fun insertBooth(boothInfo: BoothInfo) {
if (boothInfo == null) {
return
}
dataSource.addBooth(boothInfo)
}
fun removeAllBoothInfo() {
dataSource.removeAllBoothInfo()
}
fun searchBoothInfo(view: View, progressPage: ProgressPage?, boothnumber: String? = null, boothname: String? = null, boothgenre: String? = null) : Job {
return viewModelScope.launch {
removeAllBoothInfo()
val result = PythonClass.searchBoothInfo(boothnumber, boothname, boothgenre)
when {
result != null -> {
insertBooth(result)
Snackbar.make(view, "๊ฒ์์ด ์๋ฃ๋์์ต๋๋ค.",
Snackbar.LENGTH_LONG)
.show()
progressPage?.hide()
}
else -> {
Snackbar.make(
view, "๊ฒ์์ ์ค๋ฅ๊ฐ ์์ต๋๋ค.",
Snackbar.LENGTH_LONG)
.show()
progressPage?.hide()
}
}
}
}
}
@Suppress("UNCHECKED_CAST")
class BoothInfoListViewModelFactory(private val context: Context) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(SearchBoothViewModel::class.java)) {
return SearchBoothViewModel(
dataSource = DataSource.getDataSource()
) as T
}
throw illegalDecoyCallException("Unknown ViewModel Class")
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/ui/Search/SearchBoothViewModel.kt | 4293561493 |
package com.minepacu.boothlistmanager.tools.PythonCode
import android.util.Log
import com.chaquo.python.PyException
import com.chaquo.python.PyObject
import com.chaquo.python.Python
import com.minepacu.boothlistmanager.data.model.BoothInfo
import com.minepacu.boothlistmanager.data.model.Result
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
/**
* ๊ตฌ๊ธ์ ์คํ๋ ๋์ํธ์ ์ฐ๋ํ ์ ์๋ ๊ธฐ๋ฅ๋ค์ ๋ด์ ํด๋์ค
*
* @property py ํ์ด์ฌ ์ฝ๋๋ฅผ ์คํํ ์ธ์คํด์ค
* @property boothListManagementModule ํ์ด์ฌ์ผ๋ก ์ฝ๋ฉ๋ ๋ถ์ค ๊ด๋ฆฌ ๋ชจ๋
*/
class PythonClass {
companion object {
private val py = Python.getInstance()
private val boothListManagementModule =
py.getModule("BoothListManagementModule")
/**
* ๊ตฌ๊ธ API์ ๋ก๊ทธ์ธ๋ ์ ๋ณด๋ฅผ ์ ์ฅํ๋ ๊ฐ์ฒด
*/
private var loginInfo: PyObject? = null
/**
* ์ํธ์ ์ ๋ณด๋ฅผ ๋ด์ ๊ฐ์ฒด
*/
var sheetInfo: PyObject? = null
var now_WorkSheet: PyObject? = null
/**
* ๊ตฌ๊ธ API์ ๋ก๊ทธ์ธํ์ฌ ๋ฐํ๋ ๊ฐ์ฒด๋ฅผ [loginInfo]์ ์ ์ฅํฉ๋๋ค.
*
* ์ด LoginInfo ๊ฐ์ฒด๋ ํ์ด์ฌ ๋ด๋ถ์ [boothListManagementModule] ๊ฐ์ฒด ์์ gc๋ผ๋ ๋ณ์์๋
* ์๋์ผ๋ก ์ ์ฅ๋ฉ๋๋ค.
* @return [loginInfo] ๊ฐ์ฒด์ ์ ํจ ์ฌ๋ถ
* @see loginInfo
*/
suspend fun loginToGoogleAPI(): Result<Boolean> {
return withContext(Dispatchers.IO) {
Log.d("Debug", "Fun LogintoGoogleAPI is Executed")
loginInfo = boothListManagementModule.callAttr("loginService")
Log.d(
"Debug",
when {
(loginInfo == null) -> "IsNull of loginInfo : true"
else -> "IsNull of loginInfo : false"
}
)
if (loginInfo != null) {
Result.Success(true)
} else {
Result.Error(Exception("๋ก๊ทธ์ธ ๋ถ๊ฐ"))
}
}
}
/**
* ์ํธ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์์ sheetInfo ๊ฐ์ฒด์ ์ ์ฅํฉ๋๋ค.
* @return sheetInfo ๊ฐ์ฒด์ ์ ํจ ์ฌ๋ถ
*/
suspend fun getSheetInfo(sheetId: String): Result<Boolean> {
return withContext(Dispatchers.IO) {
Log.d("Debug", "Fun getsheetInfo is Executed")
sheetInfo =
boothListManagementModule.callAttr(
"getSheet", sheetId
)
Log.d(
"Debug",
when {
(sheetInfo == null) -> "IsNull of sheetInfo : true"
else -> "IsNull of sheetInfo : false"
}
)
if (sheetInfo != null) {
Result.Success(true)
} else {
Result.Error(Exception("์ํธ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ฌ ์ ์์"))
}
}
}
/**
* ๋ถ์ค ์ ๋ณด๋ฅผ ์ํธ์ ์ถ๊ฐํฉ๋๋ค.
* @param boothInfo: ์ถ๊ฐํ ๋ถ์ค์ ์ ๋ณด
* @return ํจ์ [addBoothInfoToSheet]์ ์ ์ ์ํ ์ฌ๋ถ
* @throws PyException: ํ์ด์ฌ ๋ชจ๋ ๋ด์ ์ ์๋ addBoothInfoToSheet ํจ์์์ throwํ ์์ธ
*/
suspend fun addBoothInfoToSheet(boothInfo: BoothInfo): Result<Boolean> {
return withContext(Dispatchers.IO) {
Log.d("Debug", "Fun addBoothInfoToSheet is Executed")
var result: PyObject? = null
result = boothListManagementModule.callAttr(
"addBoothInfoToSheet",
boothInfo.boothnumber,
boothInfo.boothname,
boothInfo.genres,
boothInfo.yoil,
boothInfo.InfoLabel,
boothInfo.InfoLink,
boothInfo.preorder_Date,
boothInfo.preorder_Label,
boothInfo.preorder_Link
)
Log.d("Debug", "boothname : " + boothInfo.boothname)
Log.d(
"Debug",
when {
(result == null) -> "IsNull of result from addBoothInfoToSheet : true"
else -> "IsNull of result from addBoothInfoToSheet : false"
}
)
if (result != null) {
Result.Success(true)
} else {
Result.Error(Exception("์ํธ์ ๋ถ์ค ์ ๋ณด๋ฅผ ์ถ๊ฐํ์ง ๋ชปํ์ต๋๋ค."))
}
}
}
/**
* ๋ถ์ค ์ด๋ฆ, ๋งํฌ ์ด๋ฆ, ์คํ์
๊ฐ์ ์ด์ฉํด ์
๋ฐ์ดํธ ๋ก๊ทธ๋ฅผ ์๋์ผ๋ก ๋ฑ๋กํฉ๋๋ค.
* @param boothname ์
๋ฐ์ดํธ ๋ก๊ทธ์ ๋ค์ด๊ฐ ๋ถ์ค ์ด๋ฆ
* @param linkname ์
๋ฐ์ดํธ ๋ก๊ทธ์ ๋ค์ด๊ฐ ๋งํฌ ์ด๋ฆ
* @param offset ํด๋น ๋ถ์ค๊ฐ ์ด๋ฏธ ๊ฐ์ง๊ณ ์๋ ๋งํฌ์ ์๋ก ํด๋น ๋งํฌ ์๋งํผ ์๋ ํ์ผ๋ก ๋ด๋ ค๊ฐ ๋งํฌ๋ฅผ ์ง์ ํฉ๋๋ค.
* @param mode ํด๋น ์
๋ฐ์ดํธ ๋ก๊ทธ ์ํธ๊ฐ ์ธํฌ Column์ ๋งํฌํด์ผ ํ๋ ๊ฒฝ์ฐ, 1๋ก ์ง์ ํฉ๋๋ค. ๊ทธ ์ด์ธ์๋ 0 ์ ์ฌ์ฉํ์ธ์.
*/
suspend fun addUpdateLog(boothname: String, linkname: String, offset: Int, mode: Int): Result<Boolean> {
return withContext(Dispatchers.IO) {
Log.d("Debug", "Fun addUpdateLog is Executed")
var result: PyObject? = null
result = boothListManagementModule.callAttr(
"add_UpdateLog",
boothname,
linkname,
offset,
mode)
Log.d(
"Debug",
when {
(result == null) -> "IsNull of result from addUpdateLog : true"
else -> "IsNull of result from addUpdateLog : false"
}
)
if (result != null) {
Result.Success(true)
} else {
Result.Error(Exception("์ํธ์ ๋ถ์ค ์ ๋ณด๋ฅผ ์ถ๊ฐํ์ง ๋ชปํ์ต๋๋ค."))
}
}
}
/**
* ์ง์ ํ ์ํธ ID์ ํด๋นํ๋ ์ํธ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
* @param sheetId ๊ฐ์ ธ์ค๋ ค๋ ์ํธ์ ID
* @return ํจ์์ ์ ์ ์ํ ์ฌ๋ถ
*/
suspend fun getSheet(sheetId: String): Result<Boolean> {
return withContext(Dispatchers.IO) {
Log.d("Debug", "Fun getGid is Executed")
now_WorkSheet = boothListManagementModule.callAttr("getSheet", sheetId)
Log.d(
"Debug",
when {
(now_WorkSheet == null) -> "IsNull of result from getGid : true"
else -> "IsNull of result from getGid : false"
})
if (now_WorkSheet != null) {
//Log.d("Debug", "Result : " + now_worksheet?.get("id").toString())
Result.Success(true)
} else {
Result.Error(Exception("์ํธ ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ค์ง ๋ชปํ์ต๋๋ค."))
}
}
}
/**
* ์ง์ ํ ๋งค๊ฐ ๋ณ์์ ๊ฐ์ ํด๋นํ๋ ์ํฌ์ํธ๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
* @param sheetId ์ํฌ์ํธ๊ฐ ์๋ ์ํธ์ ID
* @param sheetNumber ์ํฌ์ํธ๊ฐ ํด๋นํ๋ ์ธ๋ฑ์ค ๊ฐ, 0๋ถํฐ ์์ํฉ๋๋ค.
* @return ํจ์์ ์ ์ ์ํ ์ฌ๋ถ
*/
suspend fun getWorkSheet(sheetId: String, sheetNumber: Int): Result<Boolean> {
return withContext(Dispatchers.IO) {
Log.d("Debug", "Fun getGid is Executed")
now_WorkSheet = boothListManagementModule.callAttr("getWorkSheet", sheetId, sheetNumber)
Log.d(
"Debug",
when {
(now_WorkSheet == null) -> "IsNull of result from getGid : true"
else -> "IsNull of result from getGid : false"
})
if (now_WorkSheet != null) {
//Log.d("Debug", "Result : " + now_worksheet?.get("id").toString())
Result.Success(true)
} else {
Result.Error(Exception("์ํฌ ์ํธ ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ค์ง ๋ชปํ์ต๋๋ค."))
}
}
}
/**
* ์ง์ ํ originIndex ์์น์์ moveIndex ์์น๋ก ๋ถ์ค ๋ฐ์ดํฐ๋ฅผ ์ด๋์ํต๋๋ค.
*
* *๋งค๊ฐ ๋ณ์์ ๋ชจ๋ ์ธ๋ฑ์ค๋ ์ด๋ํ๊ธฐ ์ ์ ์ธ๋ฑ์ค ๊ฐ์ ๊ธฐ์ค์ผ๋ก ํฉ๋๋ค.*
*
* @param originIndex ์ด๋ํ๋ ค๋ ๋ถ์ค ๋ฐ์ดํฐ๊ฐ ์๋ ์ธ๋ฑ์ค
* @param moveIndex ์ด๋ํ๋ ค๋ ์์น์ ์ธ๋ฑ์ค
* @return ํจ์์ ์ ์ ์คํ ์ฌ๋ถ๋ฅผ ๊ฐ์ง [Result] ๊ฐ์ฒด
*/
suspend fun moveBoothData(originIndex: Int, moveIndex: Int) : Result<Boolean> {
return withContext(Dispatchers.IO) {
Log.d("Debug", "Fun moveBoothData is Executed")
val result = boothListManagementModule.callAttr("moveBoothData", originIndex, moveIndex)
Log.d(
"Debug",
when {
(result == null) -> "IsNull of result from getGid : true"
else -> "IsNull of result from getGid : false"
})
if (result != null) {
Result.Success(true)
} else {
Result.Error(Exception("๋ถ์ค ์ ๋ณด๋ฅผ ์ฎ๊ธฐ์ง ๋ชปํ์ต๋๋ค."))
}
}
}
/**
* ๋งค๊ฐ ๋ณ์ [boothname]์ ํด๋นํ๋ ๋ถ์ค ๋ฐ์ดํฐ์ ์ง์ ํ ๋ถ์ค ๋ฒํธ ([boothnumber])๋ฅผ ํ ๋นํฉ๋๋ค.
*
* @param boothName ๋ถ์ค ๋ฒํธ๋ฅผ ํ ๋นํ ๋ถ์ค์ ์ด๋ฆ
* @param boothNumber ํ ๋นํ ๋ถ์ค ๋ฒํธ, ์ผ๋ฐ์ ์ผ๋ก [๋ถ์ค ์ฝ๋] + [์ซ์] ์กฐํฉ์ด๋ฉฐ, [๋ถ์ค ์ฝ๋]์ ์๋ฌธ์ ์ํ๋ฒณ์ด ํฌํ๋ ๊ฒฝ์ฐ, ์๋์ผ๋ก ๋๋ฌธ์๋ก ๋ณํํฉ๋๋ค.
* @return ํ์ด์ฌ ๋ชจ๋ [boothListManagementModule] ์์ ํด๋น ๋ถ์ค๋ฅผ ์ฐพ์ผ๋ฉด ํด๋น ์
์ ์
๋ฐ์ดํธํ ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํ JSONResponse ๊ฐ์ฒด๋ฅผ ๋ฐํํ์ฌ [Result.Success]๋ฅผ ๋ฐํํ๋ฉฐ, ์ฐพ์ง ๋ชปํ๋ฉด None์ ๋ฐํํ์ฌ [Result.Error]๋ฅผ ๋ฐํํฉ๋๋ค.
*/
suspend fun putBoothNumbertoSpecificBooth(boothName: String, boothNumber: String) : Result<Boolean> {
return withContext(Dispatchers.IO) {
Log.d("Debug", "Fun putBoothNumbertoSpecificBooth is Executed")
val result = boothListManagementModule.callAttr("putBoothNumbertoSpecificBooth", boothName, boothNumber)
Log.d(
"Debug",
when {
(result == null) -> "IsNull of result from putBoothNumbertoSpecificBooth : true"
else -> "IsNull of result from putBoothNumbertoSpecificBooth : false"
})
if (result != null) {
Result.Success(true)
} else {
Result.Error(Exception("๋ถ์ค ๋ฒํธ๋ฅผ ๋ฑ๋กํ์ง ๋ชปํ์ต๋๋ค."))
}
}
}
/**
* ๋งค๊ฐ ๋ณ์ [label]์ด `//` ๋ฌธ์๋ฅผ ๊ฐ์ง ๊ฒฝ์ฐ, *TextJoin* ํจ์๋ฅผ ์ด์ฉํ์ฌ ์ค ๋ฐ๊ฟ ํฉ๋๋ค.
*
* `//` ๋ฌธ์๊ฐ ์๋ ๊ฒฝใ
, ๋งค๊ฐ ๋ณ์ [label]๋ฅผ ๊ทธ๋๋ก ๋ฐํํฉ๋๋ค.
*
* @param label ์ค ๋ฐ๊ฟํ ๋ผ๋ฒจ
* @return ์ค ๋ฐ์ด ์ฌ๋ถ๋ฅผ ์ ๊ฒ ๋ฐ ์ ์ฉํ ๋ผ๋ฒจ ๋ฌธ์์ด ๋๋ ์๋ฌ ๋ฌธ์์ด
*/
suspend fun getLabelWithTextJoin(label: String) : String {
return withContext(Dispatchers.IO) {
try {
Log.d("Debug", "Fun getLabelWithTextJoin is Executed")
val result = boothListManagementModule.callAttr("AddTextJoin", label, false)
Log.d(
"Debug",
when {
(result == null) -> "IsNull of result from AddTextJoin : true"
else -> "IsNull of result from AddTextJoin : false"
}
)
if (result != null) {
result.toString()
} else {
"result is null"
}
}
catch (e: PyException) {
"Error : " + e.message.toString()
}
}
}
suspend fun searchBoothInfo(boothNumber: String? = null, boothName: String? = null, boothGenre: String? = null) : BoothInfo? {
return withContext(Dispatchers.IO) {
try {
Log.d("Debug", "Fun searchBoothInfo is Executed")
val result = boothListManagementModule.callAttr("SearchBooth", boothNumber, boothName, boothGenre)
Log.d(
"Debug",
when {
(result == null) -> "IsNull of result from SearchBooth : true"
else -> "IsNull of result from SearchBooth : false"
}
)
when {
result != null -> {
val boothnumber: String = result.asList().get(0).toString()
val boothname: String = result.asList().get(1).toString()
val boothgenre: String = result.asList().get(2).toString()
val yoil: String = result.asList().get(3).toString()
val infoLabel: String = result.asList().get(4).toString()
val infoLink: String = result.asList().get(4).toString()
val pre_Order_Date: String = result.asList().get(5).toString()
val pre_Order_Label: String = result.asList().get(6).toString()
val pre_Order_Link: String = result.asList().get(7).toString()
BoothInfo(boothnumber, boothname, boothgenre, yoil, infoLabel, infoLink, pre_Order_Date, pre_Order_Label, pre_Order_Link)
}
else -> null
}
}
catch (e: PyException) {
Log.d("Debug", "Error : ${e.message}")
null
}
}
}
fun setVariable(variable_name: String, value: Any?) {
boothListManagementModule.put(variable_name, value)
}
fun getVariable(variable_name: String): PyObject? {
return boothListManagementModule.get(variable_name)
}
}
}
| BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/tools/PythonCode/PythonClass.kt | 2244379267 |
package com.minepacu.boothlistmanager
import android.os.Bundle
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.minepacu.boothlistmanager.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
setSupportActionBar(binding.appBarMain.topAppBar)
supportActionBar?.hide()
val navView: BottomNavigationView = binding.navView
val navController = findNavController(R.id.nav_host_fragment_activity_main)
val appBarConfiguration = AppBarConfiguration(
setOf(
R.id.nav_home, R.id.nav_addbooth, R.id.nav_serach, R.id.nav_hyperlinkgenerator, R.id.nav_preference)
)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/MainActivity.kt | 2919767717 |
package com.minepacu.boothlistmanager.data
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.minepacu.boothlistmanager.data.model.BoothInfo
class DataSource {
val temp_: BoothInfo = BoothInfo("Test", "Test", "Test", "Test", "Test", "Test", "Test", "Test", "Test")
private var initialBoothList: List<BoothInfo> = listOf(temp_)
private val boothsLiveData = MutableLiveData(initialBoothList)
fun addBooth(boothInfo: BoothInfo) {
val currentList = boothsLiveData.value
if (currentList == null) {
boothsLiveData.postValue(listOf(boothInfo))
} else {
val updatedList = currentList.toMutableList()
updatedList.add(0, boothInfo)
boothsLiveData.postValue(updatedList)
}
}
fun removeBooth(boothInfo: BoothInfo) {
val currentList = boothsLiveData.value
if (currentList != null) {
val updateedList = currentList.toMutableList()
updateedList.remove(boothInfo)
boothsLiveData.postValue(updateedList)
}
}
fun removeAllBoothInfo() {
val currentList = boothsLiveData.value
if (currentList != null) {
val updatedList = currentList.toMutableList()
updatedList.clear()
boothsLiveData.postValue(updatedList)
}
}
fun getBoothForName(name: String): BoothInfo? {
boothsLiveData.value?.let { boothInfos ->
return boothInfos.firstOrNull { it.boothname == name }
}
return null
}
fun getBoothInfoList(): LiveData<List<BoothInfo>> {
return boothsLiveData
}
companion object {
private var INSTANCE: DataSource? = null
fun getDataSource(): DataSource {
return synchronized(DataSource::class) {
val newInstance = INSTANCE ?: DataSource()
INSTANCE = newInstance
newInstance
}
}
}
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/data/DataSource.kt | 4292693235 |
package com.minepacu.boothlistmanager.data.model
import java.lang.Exception
sealed class Result<out R> {
data class Success<out T>(val data: T) : Result<T>()
data class Error(val exception: Exception) : Result<Nothing>()
} | BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/data/model/Result.kt | 3223460238 |
package com.minepacu.boothlistmanager.data.model
data class BoothInfo(var boothnumber: String?, var boothname : String, var genres : String,
var yoil : String,
var InfoLabel : String?, var InfoLink : String?,
var preorder_Date : String?, var preorder_Label : String?,
var preorder_Link : String?)
| BoothListManager_ForAndroid/app/src/main/java/com/minepacu/boothlistmanager/data/model/BoothInfo.kt | 967407163 |
package com.example.mybook
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.mybook", appContext.packageName)
}
} | My_Book/app/src/androidTest/java/com/example/mybook/ExampleInstrumentedTest.kt | 2715868811 |
package com.example.mybook
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
} | My_Book/app/src/test/java/com/example/mybook/ExampleUnitTest.kt | 3562550553 |
package com.example.mybook
import android.app.Application
import androidx.lifecycle.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject
class book_ViewModel
@Inject constructor(private val repository : book_Repository) : AndroidViewModel(
Application()
) {
private var _currentData = MutableLiveData<List<Book_Model>>()
fun insert(cigarette: Book_Model) {
viewModelScope.launch(Dispatchers.IO) {
repository.insert(cigarette)
}
}
fun delete(cigarette: Book_Model){
viewModelScope.launch(Dispatchers.IO) {
repository.delete(cigarette)
}
}
fun getAll(): LiveData<List<Book_Model>> {
return repository.getAll()
}
fun searchDatabase(searchQuery: String): LiveData<List<Book_Model>> {
return repository.searchDatabase(searchQuery).asLiveData()
}
} | My_Book/app/src/main/java/com/example/mybook/book_ViewModel.kt | 3604350479 |
package com.example.mybook
import android.app.Dialog
interface OnItemClick {
fun deleteTodo(cloths: Book_Model)
fun check_memo(content : String,book_Edit : String ,dialog : Dialog)
fun close_Dialog(dialog : Dialog)
} | My_Book/app/src/main/java/com/example/mybook/OnItemClick.kt | 4219010031 |
package com.example.mybook
import android.app.Application
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
@Module
class book_Module {
companion object {
@Singleton
@Provides
fun get_vlog_DB(context: Application): Book_Database {
return Book_Database.getInstance(context)!!
}
@Singleton
@Provides
fun get_Dao(vlog_Database: Book_Database): book_Dao {
return vlog_Database.book_dao()
}
}
} | My_Book/app/src/main/java/com/example/mybook/book_Module.kt | 3913427487 |
package com.example.mybook
import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.example.mybook.advice.*
import com.example.mybook.community.community_Activity
import com.example.mybook.create.create_Dialog
import com.example.mybook.databinding.ActivityMainBinding
import com.example.mybook.reservation.Reservation_Activity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.*
class MainActivity : AppCompatActivity(), OnItemClick, book_Adapter.OnItemClick {
private var mBinding : ActivityMainBinding ?= null
private val binding get() = mBinding!!
private lateinit var viewModel : advice_ViewModel
val handler = Handler(Looper.getMainLooper()) {
setPage()
true
}
var currentPosition = 0
var advice_List : ArrayList<String> = ArrayList()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val dexOutputDir: File = codeCacheDir
dexOutputDir.setReadOnly()
mBinding = ActivityMainBinding.inflate(layoutInflater)
CoroutineScope(Dispatchers.Main).launch {
while (true) {
delay(2000)
setPage()
}
}
binding.bookGogo.setOnClickListener {
startActivity(Intent(this@MainActivity, book_Activity::class.java))
}
binding.communityGogo.setOnClickListener {
startActivity(Intent(this@MainActivity, community_Activity::class.java))
Toast.makeText(this, "์ค๋น์ค์
๋๋ค!", Toast.LENGTH_SHORT).show()
}
binding.reservationGogo.setOnClickListener {
startActivity(Intent(this@MainActivity, Reservation_Activity::class.java))
}
val repository = advice_Repository()
val viewModelFactory = advice_Factory_ViewModel(repository)
viewModel = ViewModelProvider(this,viewModelFactory).get(advice_ViewModel::class.java)
viewModel.getAdvice()
viewModel.getAdvice2()
viewModel.getAdvice3()
viewModel.myResponse.observe(this, Observer { it ->
Log.d("ํ์ธ", it.toString())
if (it.isSuccessful) {
val body = it.body()
body?.let {
advice_List.add(it.slip!!.advice.toString())
setAdapter(advice_List,it.slip!!.advice.toString())
Log.d("์ ๋ฐ์์", advice_List.toString())
}
}
else{
Toast.makeText(this@MainActivity,it.code(), Toast.LENGTH_SHORT).show()
}
})
Log.d("์ ๋ฐ", advice_List.toString())
binding.createIntro.setOnClickListener {
val create_dialog = create_Dialog(this,this)
create_dialog.show()
}
/* val memo_dialog = book_Dailog(this,this, binding.bookContent.text.toString())
memo_dialog.show()*/
setContentView(binding.root)
}
override fun onResume() {
super.onResume()
}
private fun setPage() {
if(currentPosition == 3 ) {
currentPosition = 0
}
if(binding.viewpager11 != null) {
binding.viewpager11.setCurrentItem(currentPosition, true)
}
currentPosition += 1
}
private fun setAdapter(items: ArrayList<String>?,advice_Text : String) {
val mAdapter = advice_Adapter(items, advice_Text)
binding.viewpager11.adapter = mAdapter
}
override fun deleteTodo(cloths: Book_Model) {
TODO("Not yet implemented")
}
override fun check_memo(content: String, book_Edit: String, dialog: Dialog) {
TODO("Not yet implemented")
}
override fun close_Dialog(dialog: Dialog) {
dialog.dismiss()
}
} | My_Book/app/src/main/java/com/example/mybook/MainActivity.kt | 2924898180 |
package com.example.mybook
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class main_BarActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main_bar)
}
} | My_Book/app/src/main/java/com/example/mybook/main_BarActivity.kt | 2453662994 |
package com.example.mybook
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import kotlinx.coroutines.flow.Flow
@Dao
interface book_Dao {
@Query("SELECT * FROM book_Table ORDER BY id DESC")
fun getAll(): LiveData<List<Book_Model>>
@Insert
fun insert(cloths: Book_Model)
@Delete
fun delete(cloths: Book_Model)
@Query("SELECT * FROM book_Table WHERE book_Edit LIKE '%' || :searchQuery || '%' ORDER BY id DESC")
fun searchDatabase(searchQuery: String): Flow<List<Book_Model>>
} | My_Book/app/src/main/java/com/example/mybook/book_Dao.kt | 2552723530 |
package com.example.mybook
import android.app.Application
import androidx.lifecycle.LiveData
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
class book_Repository
@Inject
constructor(application: Application) {
private val book_dao: book_Dao
init {
var db = book_Module.get_vlog_DB(application)
book_dao = db!!.book_dao()
}
fun insert(vlog_Model: Book_Model) {
book_dao.insert(vlog_Model)
}
fun delete(vlog_Model: Book_Model){
book_dao.delete(vlog_Model)
}
fun getAll(): LiveData<List<Book_Model>> {
return book_dao.getAll()
}
fun searchDatabase(searchQuery: String): Flow<List<Book_Model>> {
return book_dao.searchDatabase(searchQuery)
}
} | My_Book/app/src/main/java/com/example/mybook/book_Repository.kt | 4012511029 |
package com.example.mybook
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.core.content.ContextCompat.startActivity
import com.example.mybook.databinding.ActivityBookDailogBinding
import com.example.mybook.reservation.Reservation_Activity
class book_Dailog(context: Context, OnItemClick: OnItemClick, var bookContent: String) : Dialog(context), View.OnClickListener {
private lateinit var binding : ActivityBookDailogBinding
var ItemClick : OnItemClick ?= null
init {
this.ItemClick = OnItemClick
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_book_dailog)
binding = ActivityBookDailogBinding.inflate(layoutInflater)
window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
binding.memoBtn.setOnClickListener {
val userInput = binding.bookEdit.text.toString()
if (userInput.isEmpty()) {
// ์
๋ ฅ์ด ๋น์ด์์ ๋ ์ฒ๋ฆฌ
Toast.makeText(context, "์ง๋ฌธ์ ์
๋ ฅํด์ฃผ์ธ์!", Toast.LENGTH_SHORT).show()
} else {
// ์
๋ ฅ์ด ๋น์ด์์ง ์์ ๋ ์ฒ๋ฆฌ
this.ItemClick?.check_memo(bookContent, userInput, this)
}
}
setContentView(binding.root)
}
override fun onClick(p0: View?) {
TODO("Not yet implemented")
}
} | My_Book/app/src/main/java/com/example/mybook/book_Dailog.kt | 1741448918 |
package com.example.mybook
import android.content.Context
import android.content.DialogInterface
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.RecyclerView
import com.example.mybook.databinding.BookItemBinding
import java.util.ArrayList
class book_Adapter(listener: OnItemClick,val itemList: List<Book_Model>, var get_context : Context) : RecyclerView.Adapter<book_Adapter.TodoViewHolder>() {
private val mCallback = listener
private val items = ArrayList<Book_Model>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : TodoViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val binding = BookItemBinding.inflate(layoutInflater)
return TodoViewHolder(binding)
}
override fun getItemCount(): Int {
return items.size
}
override fun onBindViewHolder(holder: TodoViewHolder, position: Int) {
holder.bind(items[position])
// holder.bind123(itemList[position])
holder.itemView.setOnClickListener {
}
}
inner class TodoViewHolder(private val binding: BookItemBinding): RecyclerView.ViewHolder(binding.root){
fun bind(cloths : Book_Model) {
binding.book = cloths
binding.delete.setOnClickListener {
val builder = AlertDialog.Builder(get_context)
builder.setTitle("์ญ์ ํ์๊ฒ์ต๋๊น?")
.setPositiveButton("ํ์ธ") { dialog, _ ->
mCallback.deleteTodo(cloths)
dialog.dismiss() // ๋ค์ด์ผ๋ก๊ทธ๋ฅผ ๋ซ์
}
.setNegativeButton("์ทจ์") { dialog: DialogInterface, _: Int ->
dialog.dismiss()
}
val dialog = builder.create()
dialog.show()
}
}
}
/*
fun setList(English: List<English>) {
items.clear()
items.addAll(English)
}
*/
fun setList(englishes: List<Book_Model>) {
items.clear()
items.addAll(englishes)
}
interface OnItemClick {
fun deleteTodo(cloths: Book_Model)
}
} | My_Book/app/src/main/java/com/example/mybook/book_Adapter.kt | 727985487 |
package com.example.mybook
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.animation.AnimationUtils
import com.example.mybook.databinding.ActivityBookAnswerBinding
import com.example.mybook.databinding.ActivityBookBinding
class book_AnswerActivity : AppCompatActivity() {
private var mBinding : ActivityBookAnswerBinding?= null
private val binding get() = mBinding!!
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBinding = ActivityBookAnswerBinding.inflate(layoutInflater)
val animation = AnimationUtils.loadAnimation(this, R.anim.page_flip)
binding.bookAnswer.startAnimation(animation)
setContentView(binding.root)
}
override fun onBackPressed() {
super.onBackPressed()
overridePendingTransition(R.anim.page_flip_reverse, R.anim.page_flip)
}
} | My_Book/app/src/main/java/com/example/mybook/book_AnswerActivity.kt | 3899620390 |
package com.example.mybook
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "book_Table")
class Book_Model (
var content : String,
var book_Edit : String
){
@PrimaryKey(autoGenerate = true) var id: Int = 0
} | My_Book/app/src/main/java/com/example/mybook/book_Model.kt | 3288545252 |
package com.example.mybook.reservation
import android.app.Dialog
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.util.Log
import androidx.appcompat.widget.SearchView
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.mybook.*
import com.example.mybook.databinding.ActivityReservationBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.internal.notify
import okhttp3.internal.notifyAll
class Reservation_Activity : AppCompatActivity(), OnItemClick, book_Adapter.OnItemClick{
private lateinit var binding : ActivityReservationBinding
private lateinit var book_ViewModelVar : book_ViewModel
private var SEARCH_DELAY = 300 // milliseconds
// ํธ๋ค๋ฌ๋ฅผ ์ ์ธํ์ฌ ๊ฒ์์ด ์
๋ ฅ ๋๋ ์ด๋ฅผ ๊ด๋ฆฌ
private val handler = Handler()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityReservationBinding.inflate(layoutInflater)
val repository = book_Repository(this.application)
val viewModelFactory = book_Factory(repository)
book_ViewModelVar = ViewModelProvider(this, viewModelFactory)[book_ViewModel::class.java]
book_ViewModelVar.getAll().observe(this@Reservation_Activity) {
val mAdapter = book_Adapter(this, it, this)
binding.recyclerViewBook.adapter = mAdapter
binding.recyclerViewBook.layoutManager = LinearLayoutManager(this)
mAdapter.setList(it)
Log.d("์ฒซ๋ฒ์งธ ํ์ธ",it.toString())
mAdapter.notifyDataSetChanged()
}
binding.bookSearch.isSubmitButtonEnabled = true
binding.bookSearch.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
return false
}
override fun onQueryTextChange(newText: String?): Boolean {
book_ViewModelVar.searchDatabase(newText.orEmpty()).observe(this@Reservation_Activity) { search_it ->
// ์ฌ๊ธฐ์ ํ์ฌ์ ๋ฆฌ์คํธ์ ์๋ก์ด ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐํ๊ฑฐ๋ ์
๋ฐ์ดํธ
val mAdapter = book_Adapter(this@Reservation_Activity, search_it, this@Reservation_Activity)
binding.recyclerViewBook.adapter = mAdapter
binding.recyclerViewBook.layoutManager = LinearLayoutManager(this@Reservation_Activity)
mAdapter.setList(search_it)
Log.d("์ฒซ๋ฒ์งธ ํ์ธ",search_it.toString())
mAdapter.notifyDataSetChanged()
}
return true
}
})
setContentView(binding.root)
}
override fun deleteTodo(book: Book_Model) {
book_ViewModelVar.delete(book)
}
override fun check_memo(content: String, book_Edit: String, dialog: Dialog) {
TODO("Not yet implemented")
}
override fun close_Dialog(dialog: Dialog) {
TODO("Not yet implemented")
}
} | My_Book/app/src/main/java/com/example/mybook/reservation/Reservation_Activity.kt | 1062015820 |
package com.example.mybook.advice
import com.example.mybook.advice.advice_Address.Companion.BASE_URL
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
object advice_Instance {
private val retrofit by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
val api : advice_Api by lazy {
retrofit.create(advice_Api::class.java)
}
} | My_Book/app/src/main/java/com/example/mybook/advice/advice_Instance.kt | 2802604416 |
package com.example.mybook.advice
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
class advice_Factory_ViewModel (private val repository : advice_Repository) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return advice_ViewModel(repository) as T
}
} | My_Book/app/src/main/java/com/example/mybook/advice/advice_Factory_ViewModel.kt | 2644735182 |
package com.example.mybook.advice
class advice_Address {
companion object{
const val BASE_URL = "https://api.adviceslip.com/"
}
} | My_Book/app/src/main/java/com/example/mybook/advice/advice_Address.kt | 399621155 |
package com.example.mybook.advice
import com.google.gson.annotations.SerializedName
data class Adivce_Data (
@SerializedName("slip") var slip:Slip?,
)
data class Slip (
@SerializedName("id") var id:Int?,
@SerializedName("advice") var advice:String?,
) | My_Book/app/src/main/java/com/example/mybook/advice/Adivce_Data.kt | 4068575654 |
package com.example.mybook.advice
import android.annotation.SuppressLint
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.viewpager.widget.PagerAdapter
import com.example.mybook.R
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class advice_Adapter(val advice_List: ArrayList<String>?, var advice_Text : String) : PagerAdapter() {
private var imglist = arrayListOf(R.drawable.pager_image1,R.drawable.pager_image3, R.drawable.pager_image2)
init {
}
@SuppressLint("MissingInflatedId")
override fun instantiateItem(container: ViewGroup, position: Int): Any {
var view = LayoutInflater.from(container.context).inflate(R.layout.pager_layout, container,false)
var screen_image = view.findViewById<ImageView>(R.id.pager_Image)
var screen_Advice = view.findViewById<TextView>(R.id.today_Advice)
if(advice_List!!.size == 3) {
if(imglist!!.size == 3) {
screen_image.setImageResource(imglist[position])
screen_Advice.text = advice_List!![position]
container.addView(view)
}
}
Log.d("๋ง์ง๋งํ์ธ", advice_List!!.toString())
return view
}
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
container.removeView(`object` as View?)
}
override fun getCount(): Int {
return imglist.size
}
override fun isViewFromObject(view: View, `object`: Any): Boolean {
return (view == `object`)
}
} | My_Book/app/src/main/java/com/example/mybook/advice/advice_Adapter.kt | 999749830 |
package com.example.mybook.advice
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch
import retrofit2.Response
import javax.inject.Inject
class advice_ViewModel @Inject constructor(private val repository : advice_Repository) : ViewModel() {
val myResponse : MutableLiveData<Response<Adivce_Data>> = MutableLiveData()
fun getAdvice() {
viewModelScope.launch {
val response = repository.getAdvice()
myResponse.value = response
}
}
fun getAdvice2() {
viewModelScope.launch {
val response = repository.getAdvice()
myResponse.value = response
}
}
fun getAdvice3() {
viewModelScope.launch {
val response = repository.getAdvice()
myResponse.value = response
}
}
} | My_Book/app/src/main/java/com/example/mybook/advice/advice_ViewModel.kt | 1621502914 |
package com.example.mybook.advice
import retrofit2.Response
import retrofit2.http.GET
interface advice_Api {
@GET("advice")
suspend fun getAdvice ()
: Response<Adivce_Data>
} | My_Book/app/src/main/java/com/example/mybook/advice/advice_Api.kt | 3064453248 |
package com.example.mybook.advice
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
@Module
class advice_Module {
companion object {
@Singleton
@Provides
fun getRetroInstance(): Retrofit {
return Retrofit.Builder()
.baseUrl(advice_Address.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
@Singleton
@Provides
fun getPost() : advice_Api {
//return Cancer_Instance.api.getAlbums(perpage,per,current)
return getRetroInstance().create(advice_Api::class.java)
}
}
} | My_Book/app/src/main/java/com/example/mybook/advice/advice_Module.kt | 399440531 |
package com.example.mybook.advice
import retrofit2.Response
class advice_Repository {
private val adivce_API: advice_Api
init {
var db = advice_Module.getPost()
adivce_API = db!!
}
suspend fun getAdvice() : Response<Adivce_Data> {
return adivce_API.getAdvice()
}
} | My_Book/app/src/main/java/com/example/mybook/advice/advice_Repository.kt | 620411716 |
package com.example.mybook
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
class book_Factory (private val repository : book_Repository) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return book_ViewModel(repository) as T
}
}
| My_Book/app/src/main/java/com/example/mybook/book_Factory.kt | 133418984 |
package com.example.mybook
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import com.example.mybook.databinding.ActivityEnterBinding
import java.net.InetAddress
import java.net.Socket
class activity_enter : AppCompatActivity() {
private var mBinding : ActivityEnterBinding?= null
private val binding get() = mBinding!!
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBinding = ActivityEnterBinding.inflate(layoutInflater)
binding.enterButton.setOnClickListener {
val intent = Intent(applicationContext, MainActivity::class.java)
val username: String = binding.editText.text.toString()
intent.putExtra("username", username)
startActivity(intent)
}
setContentView(binding.root)
}
} | My_Book/app/src/main/java/com/example/mybook/activity_enter.kt | 2091811457 |
package com.example.mybook
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
@Database(entities = [Book_Model::class], version = 1, exportSchema = true)
abstract class Book_Database : RoomDatabase() {
abstract fun book_dao(): book_Dao
companion object {
private var instance: Book_Database? = null
@Synchronized
fun getInstance(context: Context): Book_Database? {
if (instance == null) {
synchronized(Book_Database::class){
instance = Room.databaseBuilder(
context.applicationContext,
Book_Database::class.java,
"book_Table"
).fallbackToDestructiveMigration()
.build()
}
}
return instance
}
}
} | My_Book/app/src/main/java/com/example/mybook/Book_Database.kt | 2216224599 |
package com.example.mybook
import android.app.Dialog
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.Toast
import androidx.lifecycle.ViewModelProvider
import com.example.mybook.databinding.ActivityBookBinding
import com.google.firebase.firestore.FirebaseFirestore
class book_Activity : AppCompatActivity(), OnItemClick, book_Adapter.OnItemClick {
private var mBinding: ActivityBookBinding? = null
private val binding get() = mBinding!!
private lateinit var book_ViewModelVar: book_ViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBinding = ActivityBookBinding.inflate(layoutInflater)
binding.gopage.setOnClickListener {
startScaleDownAnimation()
}
FirebaseFirestore.getInstance().collection("Book")
.get()
.addOnSuccessListener { result ->
val contentList = mutableListOf<String>() // ์์ ๋ฆฌ์คํธ ์์ฑ
for (document in result) {
contentList.add(document.getString("Book_Content").toString())
}
// ์ฑ๊ณต ๋ฆฌ์ค๋ ๋ด์์ ๋๋ค์ผ๋ก ์ ํํ๊ณ UI์ ์ค์
binding.bookContent.text = contentList.random()
}
.addOnFailureListener {
Toast.makeText(this@book_Activity, "์คํจ", Toast.LENGTH_SHORT).show()
}
setContentView(binding.root)
}
private fun startScaleDownAnimation() {
var pagingStartAnim = AnimationUtils.loadAnimation(this, R.anim.page_flip)
var pagingEndAnim = AnimationUtils.loadAnimation(this, R.anim.scale_up_reverse_0_1)
pagingEndAnim.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationRepeat(animation: Animation?) {
}
override fun onAnimationEnd(animation: Animation?) {
binding.bookAnswer.visibility = View.VISIBLE
}
override fun onAnimationStart(animation: Animation?) {
}
})
pagingStartAnim.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationRepeat(animation: Animation?) {
}
override fun onAnimationEnd(animation: Animation?) {
binding.bookMain.startAnimation(pagingEndAnim)
binding.pageTop.setBackgroundResource(R.drawable.round_solid_white_border_d8d8d8)
}
override fun onAnimationStart(animation: Animation?) {
}
})
binding.contentReservation.setOnClickListener {
val memo_dialog = book_Dailog(this@book_Activity,this, binding.bookContent.text.toString())
memo_dialog.show()
}
val repository = book_Repository(this.application)
val viewModelFactory = book_Factory(repository)
book_ViewModelVar = ViewModelProvider(this, viewModelFactory)[book_ViewModel::class.java]
binding.bookMain.startAnimation(pagingStartAnim)
}
override fun deleteTodo(book: Book_Model) {
book_ViewModelVar.delete(book)
}
override fun check_memo(content: String, book_Edit: String, dialog: Dialog) {
book_ViewModelVar.insert(Book_Model(content,book_Edit))
Toast.makeText(this,"์ ์ฅ๋์์ต๋๋ค...", Toast.LENGTH_SHORT).show()
dialog.dismiss()
}
override fun close_Dialog(dialog: Dialog) {
TODO("Not yet implemented")
}
} | My_Book/app/src/main/java/com/example/mybook/book_Activity.kt | 2761037058 |
package com.example.mybook
import android.app.Dialog
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import com.example.mybook.databinding.ActivityLoadingScreenBinding
class loading_Screen(context: Context): Dialog(context) {
private var mBinding: ActivityLoadingScreenBinding? = null
private val binding get() = mBinding!!
lateinit var turnAround : Animation
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBinding = ActivityLoadingScreenBinding.inflate(layoutInflater)
setContentView(binding.root)
turnAround = AnimationUtils.loadAnimation(context, R.anim.turn_around)
binding.loadingImage.startAnimation(turnAround)
}
} | My_Book/app/src/main/java/com/example/mybook/loading_Screen.kt | 1062960900 |
package com.example.mybook
import java.io.IOException
import java.io.PrintWriter
import java.net.ServerSocket
import java.net.Socket
| My_Book/app/src/main/java/com/example/mybook/MyServer.kt | 3272643733 |
package com.example.mybook.community
import android.content.Intent
import android.content.SharedPreferences
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.cardview.widget.CardView
import androidx.core.view.setPadding
import androidx.recyclerview.widget.LinearLayoutManager
import coil.load
import com.example.mybook.R
import com.example.mybook.community.Comment.comment_Data
import com.example.mybook.community.Comment.comment_ListAdapter
import com.example.mybook.databinding.ActivityCommunityHolderBinding
import com.google.firebase.firestore.FieldValue
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.Query
import java.text.SimpleDateFormat
import java.util.*
class community_Holder : AppCompatActivity() {
private lateinit var binding: ActivityCommunityHolderBinding
val db = FirebaseFirestore.getInstance()
val itemList2 = arrayListOf<comment_Data>()
var adapter = comment_ListAdapter(itemList2, this)
val itemList = arrayListOf<community_Data>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCommunityHolderBinding.inflate(layoutInflater)
val view = binding.root
//setContentView(R.layout.activity_cloud_firestore)
setContentView(view)
binding.recyclerViewCommunityComment.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
binding.recyclerViewCommunityComment.adapter = adapter
//
intent = intent // ์ธํ
ํธ ๋ฐ์์ค๊ธฐ
val title = intent.getStringExtra("board_title") //Adapter์์ ๋ฐ์ ํค๊ฐ ์ฐ๊ฒฐ
val date = intent.getStringExtra("board_date")
val content = intent.getStringExtra("board_content")
val holder_doc = intent.getStringExtra("board_doc")
val password = intent.getStringExtra("board_password")
val like_count = intent.getStringExtra("board_liked")
val nickname = intent.getStringExtra("board_Nickname")
// board_title.setText(title)
// board_date.setText(content)
// board_content.setText(date)
// board_nickname.text = nickname.toString()
//likes.text = like_count.toString()
var settings: SharedPreferences = getSharedPreferences("like_tmp", MODE_PRIVATE)
var editor: SharedPreferences.Editor = settings.edit()
if(settings.getBoolean(holder_doc.toString(), false))
{
binding.notliked.visibility = View.INVISIBLE
binding.liked.visibility = View.VISIBLE
}
else
{
binding.notliked.visibility = View.VISIBLE
binding.liked.visibility = View.INVISIBLE
}
db.collection("Contacts")
.document(holder_doc.toString())
.get()
.addOnSuccessListener { result ->
try {
with(result) {
binding.boardTitle.text = "${getString("name")}"
binding.boardDate.text = "${getString("com_date")}"
binding.boardContent.text = "${getString("number")}"
binding.boardNickname.text = "${getString("nickname")}"
binding.likes.text = "${getLong("liked")}"
binding.eyeHolderCount.text = "์กฐํ์ : ${getLong("eye_count")}"
binding.realHolderImage
.load("${getString("imageUrl")}"){
placeholder(null)
error(null)
}
}
} catch (e: Exception) {
Toast.makeText(this, e.toString() , Toast.LENGTH_SHORT).show()
}
}
val go_comment_delelte = Intent(this, community_Holder::class.java)
go_comment_delelte.putExtra("board_doc", holder_doc)
//๋๊ธ์ถ๋ ฅ
db.collection("Contacts")
.document(holder_doc.toString())
.collection("Comment")// ์์
ํ ์ปฌ๋ ์
.orderBy("Date", Query.Direction.ASCENDING)
.get() // ๋ฌธ์ ๊ฐ์ ธ์ค๊ธฐ
.addOnSuccessListener { result ->
// ์ฑ๊ณตํ ๊ฒฝ์ฐ
itemList2.clear()
for (document in result) { // ๊ฐ์ ธ์จ ๋ฌธ์๋ค์ result์ ๋ค์ด๊ฐ
val item2 =
comment_Data(
document["Comment"] as String,
document["Date"] as String,
document["Doc"] as String,
document["comment_password"] as String,
document["content_doc"] as String,
document["Content_nickname"] as String,
document["Comment_liked"] as Long
)
itemList2.add(item2)
}
adapter.notifyDataSetChanged()// ๋ฆฌ์ฌ์ดํด๋ฌ ๋ทฐ ๊ฐฑ์
}
.addOnFailureListener { exception ->
// ์คํจํ ๊ฒฝ์ฐ
Log.w("TAG", "Error getting documents: $exception")
}
//
//๋๊ธ์
๋ ฅ
binding.commnetButton.setOnClickListener {
val mDialogView = LayoutInflater.from(this).inflate(R.layout.activity_comment__dialog, null)
val mBuilder = AlertDialog.Builder(this)
.setView(mDialogView)
//mBuilder.show()
val mAlertDialog = mBuilder.show()
val comment_upload = mDialogView.findViewById<CardView>(R.id.comment_upload)
val comment_cancle = mDialogView.findViewById<CardView>(R.id.comment_cancle)
val edit_nickname = mDialogView.findViewById<EditText>(R.id.edit_nickname)
val edit_password = mDialogView.findViewById<EditText>(R.id.edit_password)
comment_upload.setOnClickListener {
var comment_edit = binding.commentEdit.text.toString()
val currentTime: Long = System.currentTimeMillis()
val simpleDate = SimpleDateFormat("yyyy-MM-dd k:mm:ss")
val mDate: Date = Date(currentTime)
val getTime = simpleDate.format(mDate)
val content_doc = holder_doc.toString()
val content_nickname = edit_nickname.text.toString()
val doc = UUID.randomUUID().toString()
val data = hashMapOf(
"Comment" to comment_edit,
"Date" to getTime.toString(),
"Doc" to doc,
"comment_password" to edit_password.text.toString(),
"content_doc" to content_doc,
"Content_nickname" to content_nickname,
"Comment_liked" to 0.toLong()
)
db.collection("Contacts")
.document(holder_doc.toString())
.collection("Comment")
.document(doc.toString())
.set(data)
.addOnSuccessListener {
// ์ฑ๊ณตํ ๊ฒฝ์ฐ
Toast.makeText(this, "๋ฐ์ดํฐ๊ฐ ์ถ๊ฐ๋์์ต๋๋ค", Toast.LENGTH_SHORT).show()
update()
mAlertDialog.dismiss()
//go_board2.putExtra("board_doc", it.toString())
// startActivity(go_board2)
}
.addOnFailureListener { exception ->
// ์คํจํ ๊ฒฝ์ฐ
Log.w("MainActivity", "Error getting documents: $exception")
}
}
comment_cancle.setOnClickListener {
mAlertDialog.dismiss()
}
}
binding.liked.setOnClickListener {
binding.notliked.visibility = View.VISIBLE
binding.liked.visibility = View.INVISIBLE
db.collection("Contacts")
.document(holder_doc.toString())
.update("liked", FieldValue.increment(-1))
.addOnSuccessListener { result ->
db.collection("Contacts")
.document(holder_doc.toString())
.get()
.addOnSuccessListener { result ->
try {
with(result) {
binding.likes.text = "${getLong("liked")}"
editor.remove(holder_doc.toString())
editor.commit()
}
} catch (e: Exception) {
Toast.makeText(this, e.toString() , Toast.LENGTH_SHORT).show()
}
}
Toast.makeText(this, "์ข์์๋ฅผ ์ทจ์ํ์ต๋๋ค.", Toast.LENGTH_SHORT).show()
}
.addOnFailureListener { exception ->
Toast.makeText(this, exception.toString(), Toast.LENGTH_SHORT).show()
}
}
binding.notliked.setOnClickListener {
binding.notliked.visibility = View.INVISIBLE
binding.liked.visibility = View.VISIBLE
//์ฌ๊ธฐ์ ๋ถํฐ ์์
db.collection("Contacts")
.document(holder_doc.toString())
.update("liked", FieldValue.increment(1))
.addOnSuccessListener { result ->
//
db.collection("Contacts")
.document(holder_doc.toString())
.get()
.addOnSuccessListener { result ->
try {
with(result) {
binding.likes.text = "${getLong("liked")}"
editor.putBoolean(holder_doc.toString(), true)
editor.commit()
}
} catch (e: Exception) {
Toast.makeText(this, e.toString() , Toast.LENGTH_SHORT).show()
}
}
//
Toast.makeText(this, "์ข์์๋ฅผ ๋๋ ์ต๋๋ค.", Toast.LENGTH_SHORT).show()
}
.addOnFailureListener { exception ->
Toast.makeText(this, exception.toString(), Toast.LENGTH_SHORT).show()
}
}
binding.contentDelete.setOnClickListener {
val builder = AlertDialog.Builder(this)
val tvName = TextView(this)
tvName.text = "\n๋น๋ฐ๋ฒํธ ์
๋ ฅ\n"
val password_edit = EditText(this)
password_edit.isSingleLine = true
val mLayout = LinearLayout(this)
mLayout.orientation = LinearLayout.VERTICAL
mLayout.setPadding(16)
mLayout.addView(tvName)
mLayout.addView(password_edit)
builder.setView(mLayout)
builder.setTitle("๊ฒ์๋ฌผ ์ญ์ ")
builder.setPositiveButton("์ญ์ ") { dialog, which ->
// EditText์์ ๋ฌธ์์ด์ ๊ฐ์ ธ์ hashMap์ผ๋ก ๋ง๋ฆ
if(password_edit.text.toString().equals(password.toString())) {
db.collection("Contacts")
.document(holder_doc.toString())
.delete()
.addOnSuccessListener {
// ์ฑ๊ณตํ ๊ฒฝ์ฐ
Toast.makeText(this, "์ฑ๊ณต์ ์ผ๋ก ์ญ์ ๋์์ต๋๋ค.", Toast.LENGTH_SHORT).show()
finish()
//go_board2.putExtra("board_doc", it.toString())
// startActivity(go_board2)
}
.addOnFailureListener { exception ->
// ์คํจํ ๊ฒฝ์ฐ
Log.w("MainActivity", "Error getting documents: $exception")
}
} else {
Toast.makeText(this, "๋น๋ฐ๋ฒํธ๊ฐ ์ผ์นํ์ง์์ต๋๋ค.", Toast.LENGTH_SHORT).show()
}
}
builder.setNegativeButton("์ทจ์") { dialog, which ->
}
builder.show()
}
}
fun update() {
val content_doc = intent.getStringExtra("board_doc")
db.collection("Contacts")
.document(content_doc.toString())
.collection("Comment")// ์์
ํ ์ปฌ๋ ์
.orderBy("Date", Query.Direction.ASCENDING)
.get() // ๋ฌธ์ ๊ฐ์ ธ์ค๊ธฐ
.addOnSuccessListener { result ->
// ์ฑ๊ณตํ ๊ฒฝ์ฐ
itemList2.clear()
for (document in result) { // ๊ฐ์ ธ์จ ๋ฌธ์๋ค์ result์ ๋ค์ด๊ฐ
val item2 =
comment_Data(
document["Comment"] as String,
document["Date"] as String,
document["Doc"] as String,
document["comment_password"] as String,
document["content_doc"] as String,
document["Content_nickname"] as String,
document["Comment_liked"] as Long)
itemList2.add(item2)
}
adapter.notifyDataSetChanged()// ๋ฆฌ์ฌ์ดํด๋ฌ ๋ทฐ ๊ฐฑ์
binding.commentEdit.setText("")
}
.addOnFailureListener { exception ->
// ์คํจํ ๊ฒฝ์ฐ
Log.w("TAG", "Error getting documents: $exception")
}
}
} | My_Book/app/src/main/java/com/example/mybook/community/community_Holder.kt | 1448544741 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.