forked from Helium314/HeliBoard
-
Notifications
You must be signed in to change notification settings - Fork 2
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
PR for New UI changes #2
Merged
Merged
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
0480c15
local commit for kalyani
kalyaniboya dbcfd9e
local commit for kalyani
kalyaniboya 880e081
local commit for kalyani
kalyaniboya 5d5acdd
local commit for kalyani
kalyaniboya de43d7b
local commit for kalyani
kalyaniboya 0b2f5d7
local commit for kalyani
kalyaniboya 86dcb04
Change App name
surajsahani 7e476be
AI Engine
surajsahani d3ffefa
Merge remote-tracking branch 'origin/feature_ui/develop' into feature…
surajsahani e4020db
app name changes | ViewModel Handling
surajsahani 333189f
viewModel handling
surajsahani 8e1d45f
AI added | UI improvement
surajsahani 9a42c5a
Keyboard changes
surajsahani 48502d0
UI improved
surajsahani 50e51ce
button ui setup done
kalyaniboya b809200
setting and drawer items is working fine
kalyaniboya c17a6ed
button colors are working fine
kalyaniboya 1029e3c
check icon
kalyaniboya 841f707
working fine
kalyaniboya 2d51800
Added icons in Heliboard
surajsahani 6e81be7
onbackpressed is done
kalyaniboya 04d0c37
adding ai logo
surajsahani b95580b
onbackpressed is done
kalyaniboya d12e44f
Merge remote-tracking branch 'origin/feature_aiEngine/develop' into f…
kalyaniboya 3f88ee3
ui edge cases fixing
kalyaniboya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package helium314.keyboard.AIEngine | ||
|
||
import com.mohamedrejeb.richeditor.model.RichTextState | ||
|
||
data class AIState( | ||
val isAIProcessing: Boolean = false, | ||
val isAICorrecting: Boolean = false, | ||
val aiText: RichTextState = RichTextState(), | ||
) |
47 changes: 47 additions & 0 deletions
47
app/src/main/java/helium314/keyboard/AIEngine/SummarizeUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package helium314.keyboard.AIEngine | ||
|
||
/** | ||
* A sealed hierarchy describing the state of the text generation. | ||
*/ | ||
sealed interface SummarizeUiState { | ||
|
||
/** | ||
* Empty state when the screen is first shown | ||
*/ | ||
data object Initial: SummarizeUiState | ||
|
||
/** | ||
* Still loading | ||
*/ | ||
data object Loading: SummarizeUiState | ||
|
||
/** | ||
* Text has been generated | ||
*/ | ||
data class Success( | ||
val outputText: String | ||
): SummarizeUiState | ||
|
||
/** | ||
* There was an error generating text | ||
*/ | ||
data class Error( | ||
val errorMessage: String | ||
): SummarizeUiState | ||
} |
108 changes: 108 additions & 0 deletions
108
app/src/main/java/helium314/keyboard/AIEngine/SummarizeViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package helium314.keyboard.AIEngine | ||
|
||
import android.content.Context | ||
import android.widget.Toast | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.google.ai.client.generativeai.GenerativeModel | ||
import com.google.ai.client.generativeai.type.content | ||
import helium314.keyboard.gemini.GeminiClient | ||
import helium314.keyboard.latin.utils.Log | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.update | ||
import kotlinx.coroutines.launch | ||
|
||
class SummarizeViewModel( | ||
private val generativeModel: GenerativeModel | ||
) : ViewModel() { | ||
|
||
private val _state = MutableStateFlow(AIState()) | ||
val state: StateFlow<AIState> = _state.asStateFlow() | ||
|
||
|
||
private val _aiState = MutableLiveData<AIState>() | ||
val replyData: LiveData<AIState> | ||
get() = _aiState | ||
|
||
private val _isAICorrecting = MutableLiveData<Boolean>() | ||
val isAICorrecting: LiveData<Boolean> | ||
get() = _isAICorrecting | ||
|
||
private val _uiState: MutableStateFlow<SummarizeUiState> = | ||
MutableStateFlow(SummarizeUiState.Initial) | ||
val uiState: StateFlow<SummarizeUiState> = | ||
_uiState.asStateFlow() | ||
|
||
// fun onAICorrection(context: Context) { | ||
// | ||
// val generativeModel = geminiClient.geminiFlashModel | ||
// | ||
// val inputContent = content { | ||
// text("Please correct the following text for any spelling and grammatical errors, and slightly paraphrase it while keeping the original language and the markdown format:\n") | ||
// } | ||
// viewModelScope.launch { | ||
// try { | ||
// val response = generativeModel.generateContent(inputContent) | ||
// _state.update { it.copy(isAICorrecting = true) } | ||
// Toast.makeText(context, "Text Corrected With AIEngine", Toast.LENGTH_SHORT).show() | ||
// } catch (e: Exception) { | ||
// Toast.makeText(context, "Error Correcting Text With AIEngine", Toast.LENGTH_SHORT) | ||
// .show() | ||
// } finally { | ||
// _state.update { it.copy(isAICorrecting = false) } | ||
// } | ||
// } | ||
// } | ||
|
||
fun summarizeStreaming(inputText: String) { | ||
_uiState.value = SummarizeUiState.Loading | ||
|
||
val prompt = | ||
"Please correct the following text for any spelling and grammatical errors, and slightly paraphrase it while keeping the original language and the markdown format:\n: $inputText" | ||
|
||
viewModelScope.launch { | ||
try { | ||
var outputContent = "" | ||
generativeModel.generateContentStream(prompt) | ||
.collect { response -> | ||
outputContent += response.text | ||
_uiState.value = SummarizeUiState.Success(outputContent) | ||
Log.d("SummarizeViewModel", "outputContent: $outputContent") | ||
} | ||
} catch (e: Exception) { | ||
_uiState.value = SummarizeUiState.Error(e.localizedMessage ?: "") | ||
Log.d("SummarizeViewModel", "Error: ${e.localizedMessage}") | ||
} | ||
} | ||
} | ||
|
||
// fun summarizeStreamingLiveData(inputText: String) { | ||
// //_uiState.value = SummarizeUiState.Loading | ||
// | ||
// val prompt = | ||
// "Please correct the following text for any spelling and grammatical errors, and slightly paraphrase it while keeping the original language and the markdown format:\n: $inputText" | ||
// | ||
// viewModelScope.launch { | ||
// try { | ||
// var outputContent = "" | ||
// val response = generativeModel.generateContentStream(prompt) | ||
// val response = AIState(prompt) | ||
// _aiState.postValue(response) | ||
// | ||
// //_aiState.value = generativeModel.generateContentStream(prompt) | ||
// | ||
//// .collect { response -> | ||
//// outputContent += response.text | ||
//// _uiState.value = SummarizeUiState.Success(outputContent) | ||
//// } | ||
// } catch (e: Exception) { | ||
// _uiState.value = SummarizeUiState.Error(e.localizedMessage ?: "") | ||
// } | ||
// } | ||
// } | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/helium314/keyboard/AIEngine/SummarizeViewModelFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package helium314.keyboard.AIEngine | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.google.ai.client.generativeai.GenerativeModel | ||
import helium314.keyboard.gemini.GeminiClient | ||
|
||
class SummarizeViewModelFactory( | ||
//private val geminiClient: GeminiClient, | ||
private val generativeModel: GenerativeModel | ||
) : ViewModelProvider.Factory { | ||
|
||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
if (modelClass.isAssignableFrom(SummarizeViewModel::class.java)) { | ||
@Suppress("UNCHECKED_CAST") | ||
return SummarizeViewModel( generativeModel) as T | ||
} | ||
throw IllegalArgumentException("Unknown ViewModel class") | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
app/src/main/java/helium314/keyboard/bottomsheets/SheetOneFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package helium314.keyboard.bottomsheets | ||
|
||
|
||
import android.content.Intent | ||
import android.graphics.Color | ||
import android.graphics.Typeface | ||
import android.os.Bundle | ||
import android.text.SpannableString | ||
import android.text.Spanned | ||
import android.text.style.ForegroundColorSpan | ||
import android.text.style.StyleSpan | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import android.widget.TextView | ||
import helium314.keyboard.latin.R | ||
import android.provider.Settings | ||
|
||
class SheetOneFragment : Fragment() { | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
var view = inflater.inflate(R.layout.fragment_sheet1, container, false) | ||
|
||
val instructionText = | ||
"Tap the toggle to enable Oscar Keyboard in \n your keyboard list" | ||
val spannableString = SpannableString(instructionText) | ||
|
||
val startIndex = instructionText.indexOf("Oscar Keyboard") | ||
val endIndex = startIndex + "Oscar Keyboard".length | ||
|
||
if (startIndex >= 0) { | ||
spannableString.setSpan( | ||
ForegroundColorSpan(Color.BLACK), // Set color to black | ||
startIndex, | ||
endIndex, | ||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | ||
) | ||
|
||
spannableString.setSpan( | ||
StyleSpan(Typeface.BOLD), // Set style to bold | ||
startIndex, | ||
endIndex, | ||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | ||
) | ||
} | ||
|
||
val textViewInstruction = view.findViewById<TextView>(R.id.text_view_instruction) | ||
textViewInstruction.text = spannableString | ||
|
||
val buttonEnable = view.findViewById<Button>(R.id.enableId) | ||
buttonEnable.setOnClickListener { | ||
// Open the system settings to enable the keyboard | ||
startActivity(Intent(Settings.ACTION_INPUT_METHOD_SETTINGS)) | ||
} | ||
|
||
return view | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this if we don't need