Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development to Master #54

Merged
merged 5 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<img src="app_icon.png" title="App Logo">
<img src="app_icon.png" title="App Logo" alt="">
</p>

# StackOverflow - Community Version
Expand All @@ -25,7 +25,7 @@ Users can also search for a particular problem they are having by typing in a se
* [Preferences DataStore](https://developer.android.com/topic/libraries/architecture/datastore) for storing and retrieving key-value pairs of primitive data types
# Installation

This App requires a minimum API level of 21. Clone the repository. You will need an API key from [Stack Exchange API](https://api.stackexchange.com/) to receive a higher request quota. Locate the StringConstants.java file and edit the following line to add your API key:
This App requires a minimum API level of 26. Clone the repository. You will need an API key from [Stack Exchange API](https://api.stackexchange.com/) to receive a higher request quota. Locate the StringConstants.java file and edit the following line to add your API key:

````
API_KEY = "YOUR_API_KEY"
Expand Down
7 changes: 7 additions & 0 deletions android_glide_lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- https://github.com/bumptech/glide/issues/4940 -->
<lint>
<issue id="NotificationPermission">
<ignore regexp="com.bumptech.glide.request.target.NotificationTarget" />
</issue>
</lint>
50 changes: 28 additions & 22 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.dagger.hilt.android'

android {
compileSdkVersion 31
buildToolsVersion "29.0.3"
namespace 'com.josycom.mayorjay.flowoverstack'
compileSdk 34

defaultConfig {
applicationId "com.josycom.mayorjay.flowoverstack"
minSdkVersion 21
targetSdkVersion 31
versionCode 8
versionName "1.8"
minSdk 26
targetSdk 34
versionCode 200
versionName "2.00"
multiDexEnabled true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -50,20 +51,30 @@ android {

buildFeatures {
viewBinding true
buildConfig true
}

compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 17
targetCompatibility = 17
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
jvmTarget = JavaVersion.VERSION_17
freeCompilerArgs += [
"-Xjvm-default=all",
]
}

kapt {
correctErrorTypes true
}

lint {
// https://github.com/bumptech/glide/issues/4940
lintConfig = file("$rootDir/android_glide_lint.xml")
}

}

dependencies {
Expand Down Expand Up @@ -106,10 +117,6 @@ dependencies {
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata:2.4.0"

// RxAndroid and RxJava
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.7'

// SwipeRefreshLayout
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

Expand All @@ -124,20 +131,19 @@ dependencies {
implementation 'com.github.mukeshsolanki:MarkdownView-Android:1.0.8'

// Image cropper
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'com.vanniktech:android-image-cropper:4.3.3'

// ML Kit
implementation 'com.google.android.gms:play-services-mlkit-text-recognition:17.0.0'

// Dagger
implementation 'com.google.dagger:dagger:2.35.1'
implementation 'com.google.dagger:dagger-android:2.35.1'
implementation 'com.google.dagger:dagger-android-support:2.27'
annotationProcessor 'com.google.dagger:dagger-compiler:2.35.1'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.35.1'
// Hilt
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"

// Play core
implementation 'com.google.android.play:core:1.10.2'
implementation 'com.google.android.play:asset-delivery:2.2.2'
implementation 'com.google.android.play:feature-delivery:2.1.0'
implementation 'com.google.android.play:app-update:2.1.0'

// Kotlin
implementation 'androidx.core:core-ktx:1.6.0'
Expand Down
19 changes: 7 additions & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.josycom.mayorjay.flowoverstack">

<uses-feature
android:name="android.hardware.camera"
android:required="false" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32" tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
Expand Down Expand Up @@ -56,22 +61,12 @@
android:theme="@style/AppTheme.NoActionBar">

</activity>
<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity" />
<activity android:name="com.canhub.cropper.CropImageActivity" />

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />

<provider
android:authorities="com.josycom.mayorjay.flowoverstack.fileprovider"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_path"/>
</provider>

</application>

</manifest>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.josycom.mayorjay.flowoverstack

import android.app.Application
import com.josycom.mayorjay.flowoverstack.util.AppLogger
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class MyApplication : Application() {

override fun onCreate() {
super.onCreate()
AppLogger.init()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package com.josycom.mayorjay.flowoverstack.data.remote.model
import com.josycom.mayorjay.flowoverstack.data.model.Question

data class SearchResponse(
val networkState: String,
val questions: List<Question>?
val networkState: String = "",
val questions: List<Question>? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface ApiService {
@Query("site") site: String?,
@Query("tagged") tagged: String?,
@Query(value = "filter", encoded = true) filter: String?,
@Query("key") siteKey: String?): QuestionsResponse
@Query("key", encoded = true) siteKey: String?): QuestionsResponse

@GET(AppConstants.ANSWERS_END_POINT)
suspend fun getAnswersToQuestion(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package com.josycom.mayorjay.flowoverstack.data.repository

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.emptyPreferences
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.josycom.mayorjay.flowoverstack.util.AppConstants
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map
import timber.log.Timber
import javax.inject.Inject

val Context.dataStore: DataStore<Preferences> by preferencesDataStore(
name = AppConstants.PREFERENCES_FILE_NAME
)

class PreferenceRepositoryImpl(private val dataStore: DataStore<Preferences>) :
class PreferenceRepositoryImpl @Inject constructor(private val dataStore: DataStore<Preferences>) :
PreferenceRepository {

override fun getIntPreferenceFlow(key: String): Flow<Int?> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,35 @@ import javax.inject.Singleton
@Singleton
class SearchRepository @Inject constructor(private val apiService: ApiService) {

private val mResponse = MutableLiveData<SearchResponse>()
val searchResponse = MutableLiveData<SearchResponse>()

private fun getQuestionsWithTextInTitle(inTitle: String?, page: Int, pageSize: Int) {
mResponse.postValue(SearchResponse(AppConstants.LOADING, null))
searchResponse.postValue(SearchResponse(AppConstants.LOADING, null))
val call = apiService.getQuestionsWithTextInTitle(inTitle, page, pageSize)
call.enqueue(object : Callback<QuestionsResponse?> {
override fun onResponse(call: Call<QuestionsResponse?>, response: Response<QuestionsResponse?>) {
val questionsResponse = response.body()
if (questionsResponse != null) {
if (questionsResponse.items.isNotEmpty()) {
mResponse.setValue(
searchResponse.setValue(
SearchResponse(
AppConstants.LOADED,
questionsResponse.items.map { it.toQuestion() })
)
} else {
mResponse.setValue(SearchResponse(AppConstants.NO_MATCHING_RESULT, null))
searchResponse.setValue(SearchResponse(AppConstants.NO_MATCHING_RESULT, null))
}
}
}

override fun onFailure(call: Call<QuestionsResponse?>, t: Throwable) {
Timber.e(t)
mResponse.value = SearchResponse(AppConstants.FAILED, null)
searchResponse.value = SearchResponse(AppConstants.FAILED, null)
}
})
}

fun getResponse(inTitle: String?, page: Int, pageSize: Int): MutableLiveData<SearchResponse> {
fun performSearch(inTitle: String?, page: Int, pageSize: Int) {
ThreadExecutor.mExecutor.execute { getQuestionsWithTextInTitle(inTitle, page, pageSize) }
return mResponse
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.josycom.mayorjay.flowoverstack.di

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.josycom.mayorjay.flowoverstack.BuildConfig
import com.josycom.mayorjay.flowoverstack.data.remote.service.ApiService
import com.josycom.mayorjay.flowoverstack.util.AppConstants
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
object ApiModule {

@Provides
@Singleton
fun provideGson(): Gson = GsonBuilder().setLenient().create()

@Provides
@Singleton
fun provideInterceptor(): HttpLoggingInterceptor =
HttpLoggingInterceptor()
.setLevel(if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE)

@Provides
@Singleton
fun getOkHttpClient(interceptor: HttpLoggingInterceptor): OkHttpClient.Builder =
OkHttpClient.Builder().addInterceptor(interceptor)

@Provides
@Singleton
fun provideRetrofit(gson: Gson, okHttpClient: OkHttpClient.Builder): Retrofit =
Retrofit.Builder()
.baseUrl(AppConstants.BASE_URL)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.client(okHttpClient.build())
.build()

@Provides
@Singleton
fun getApiService(retrofit: Retrofit): ApiService = retrofit.create(ApiService::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.josycom.mayorjay.flowoverstack.di

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStoreFile
import com.josycom.mayorjay.flowoverstack.util.AppConstants
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
object DataStoreModule {

@Provides
@Singleton
fun provideDataStore(@ApplicationContext context: Context): DataStore<Preferences> =
PreferenceDataStoreFactory.create(
produceFile = {
context.preferencesDataStoreFile(AppConstants.PREFERENCES_FILE_NAME)
}
)
}
Loading