Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/devtest'
Browse files Browse the repository at this point in the history
  • Loading branch information
TBog committed Apr 25, 2024
2 parents b8d55c9 + f1c4a17 commit 0b11a77
Show file tree
Hide file tree
Showing 23 changed files with 231 additions and 112 deletions.
10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/palantir-java-format.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
Expand Down
167 changes: 106 additions & 61 deletions app/src/main/java/rocks/tbog/tblauncher/Behaviour.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.os.Bundle;
import android.provider.Settings;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
Expand All @@ -42,7 +43,6 @@
import androidx.recyclerview.widget.RecyclerView;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -108,7 +108,6 @@ public class Behaviour implements ISearchActivity {
private static final String TAG = Behaviour.class.getSimpleName();
private TBLauncherActivity mTBLauncherActivity = null;
private DialogFragment<?> mFragmentDialog = null;

private View mResultLayout;
private RecyclerList mResultList;
private RecycleAdapter mResultAdapter;
Expand All @@ -131,6 +130,7 @@ public void run() {
mLauncherTime.postDelayed(mUpdateTime, delay);
}
};
private boolean mLaunchMostRelevantResult = false;
private final TextWatcher mSearchTextWatcher = new TextWatcher() {
@NonNull
String lastText = "";
Expand All @@ -147,9 +147,9 @@ public void afterTextChanged(Editable s) {
s.delete(0, spaceEnd);
} else {
String text = s.toString();
if (lastText.equals(text))
if (lastText.equals(text) || mLaunchMostRelevantResult)
return;
if (text == null || text.isEmpty())
if (TextUtils.isEmpty(text))
clearAdapter();
else
updateSearchRecords(false, text);
Expand Down Expand Up @@ -383,11 +383,16 @@ private void initLauncherSearchEditText() {
}

// launch most relevant result
final int mostRelevantIdx = mResultList.getAdapterFirstItemIdx();
if (mostRelevantIdx >= 0 && mostRelevantIdx < mResultAdapter.getItemCount()) {
RecyclerView.ViewHolder holder = mResultList.findViewHolderForAdapterPosition(mostRelevantIdx);
mResultAdapter.onClick(mostRelevantIdx, holder != null ? holder.itemView : view);
if (TBApplication.hasSearchTask(getContext())) {
mLaunchMostRelevantResult = true;
return true;
} else {
final int mostRelevantIdx = mResultList.getAdapterFirstItemIdx();
if (mostRelevantIdx >= 0 && mostRelevantIdx < mResultAdapter.getItemCount()) {
RecyclerView.ViewHolder holder = mResultList.findViewHolderForAdapterPosition(mostRelevantIdx);
mResultAdapter.onClick(mostRelevantIdx, holder != null ? holder.itemView : view);
return true;
}
}
return false;
});
Expand Down Expand Up @@ -623,7 +628,7 @@ public void switchToDesktop(@NonNull LauncherState.Desktop mode) {
switch (currentMode) {
case SEARCH:
resetTask();
hideSearchBar(true);
hideSearchBar();
break;
case WIDGET:
hideWidgets();
Expand Down Expand Up @@ -677,7 +682,7 @@ private void showDesktop(LauncherState.Desktop mode) {
break;
case WIDGET:
// show widgets
showWidgets(true);
showWidgets();
// hide/show the QuickList
TBApplication.quickList(getContext()).updateVisibility();
// enable/disable fullscreen (status and navigation bar)
Expand Down Expand Up @@ -786,7 +791,8 @@ private void showSearchBar() {
setSearchHint();
UITheme.applySearchBarTextShadow(mSearchEditText);

mSearchBarContainer.animate().cancel();
if (TBApplication.state().getSearchBarVisibility() != LauncherState.AnimatedVisibility.ANIM_TO_VISIBLE)
mSearchBarContainer.animate().cancel();
mSearchBarContainer.setVisibility(View.VISIBLE);
mSearchBarContainer.animate()
.setStartDelay(0)
Expand Down Expand Up @@ -822,41 +828,54 @@ private void hideWidgets() {
mWidgetContainer.setVisibility(View.GONE);
}

private void hideSearchBar() {
boolean animate = !TBApplication.state().isSearchBarVisible();
hideSearchBar(animate);
}

private void hideSearchBar(boolean animate) {
clearSearchText();
clearAdapter();

final float translationY;
if (PrefCache.searchBarAtBottom(mPref))
translationY = mSearchBarContainer.getHeight() * 2f;
else
translationY = mSearchBarContainer.getHeight() * -2f;

mSearchBarContainer.animate().cancel();
if (animate) {
mSearchBarContainer.animate()
.alpha(0f)
.translationY(translationY)
.setDuration(UI_ANIMATION_DURATION)
.setInterpolator(new AccelerateInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
TBApplication.state().setSearchBar(LauncherState.AnimatedVisibility.ANIM_TO_HIDDEN);
}

@Override
public void onAnimationEnd(Animator animation) {
TBApplication.state().setSearchBar(LauncherState.AnimatedVisibility.HIDDEN);
mSearchBarContainer.setVisibility(View.GONE);
}
})
.start();
if (mSearchBarContainer.getVisibility() == View.VISIBLE) {
final float translationY;
if (PrefCache.searchBarAtBottom(mPref))
translationY = mSearchBarContainer.getHeight() * 2f;
else
translationY = mSearchBarContainer.getHeight() * -2f;

if (TBApplication.state().getSearchBarVisibility() != LauncherState.AnimatedVisibility.ANIM_TO_HIDDEN)
mSearchBarContainer.animate().cancel();

if (animate) {
mSearchBarContainer.setTranslationY(0f);
mSearchBarContainer.animate()
.alpha(0f)
.translationY(translationY)
.setDuration(UI_ANIMATION_DURATION)
.setInterpolator(new AccelerateInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
TBApplication.state().setSearchBar(LauncherState.AnimatedVisibility.ANIM_TO_HIDDEN);
}

@Override
public void onAnimationEnd(Animator animation) {
TBApplication.state().setSearchBar(LauncherState.AnimatedVisibility.HIDDEN);
mSearchBarContainer.setVisibility(View.GONE);
}
})
.start();
} else {
TBApplication.state().setSearchBar(LauncherState.AnimatedVisibility.HIDDEN);
mSearchBarContainer.setAlpha(0f);
mSearchBarContainer.setTranslationY(translationY);
mSearchBarContainer.setVisibility(View.GONE);
}
} else {
TBApplication.state().setSearchBar(LauncherState.AnimatedVisibility.HIDDEN);
mSearchBarContainer.setAlpha(0f);
mSearchBarContainer.setTranslationY(translationY);
mSearchBarContainer.setVisibility(View.GONE);
Log.d(TAG, "mSearchBarContainer not VISIBLE, setting state to HIDDEN");
TBApplication.state().setResultList(LauncherState.AnimatedVisibility.HIDDEN);
}

if (PrefCache.linkKeyboardAndSearchBar(mPref))
Expand All @@ -865,14 +884,15 @@ public void onAnimationEnd(Animator animation) {
mSearchEditText.setEnabled(false);
}

private void showWidgets() {
boolean animate = !TBApplication.state().isWidgetScreenVisible();
showWidgets(animate);
}

private void showWidgets(boolean animate) {
if (TBApplication.state().getWidgetScreenVisibility() != LauncherState.AnimatedVisibility.ANIM_TO_VISIBLE)
mWidgetContainer.animate().cancel();
if (mWidgetContainer.getVisibility() == View.VISIBLE) {
mWidgetContainer.setAlpha(1f);
hideResultList(false);
return;
}
mSearchBarContainer.animate().cancel();

mWidgetContainer.setVisibility(View.VISIBLE);
if (animate) {
mWidgetContainer.setAlpha(0f);
Expand All @@ -894,10 +914,11 @@ public void onAnimationEnd(Animator animation) {
})
.start();
} else {
mWidgetContainer.animate().cancel();
TBApplication.state().setWidgetScreen(LauncherState.AnimatedVisibility.VISIBLE);
mWidgetContainer.setAlpha(1f);
}
hideResultList(true);
hideResultList(animate);
}

public void showKeyboard() {
Expand Down Expand Up @@ -1011,6 +1032,22 @@ public void updateAdapter(@NonNull List<? extends EntryItem> results, boolean is
mTBLauncherActivity.quickList.adapterUpdated();
mClearButton.setVisibility(View.VISIBLE);
mMenuButton.setVisibility(View.INVISIBLE);

if (mLaunchMostRelevantResult) {
mLaunchMostRelevantResult = false;

// get any view
View view = mResultList.getLayoutManager() != null ? mResultList.getLayoutManager().getChildAt(0) : null;
final int mostRelevantIdx = mResultList.getAdapterFirstItemIdx();
// try to get view of the most relevant item from adapter
if (mostRelevantIdx >= 0 && mostRelevantIdx < mResultAdapter.getItemCount()) {
RecyclerView.ViewHolder holder = mResultList.findViewHolderForAdapterPosition(mostRelevantIdx);
if (holder != null)
view = holder.itemView;
}
if (view != null)
mResultAdapter.onClick(mostRelevantIdx, view);
}
}

@Override
Expand Down Expand Up @@ -1045,7 +1082,7 @@ public void runSearcher(@NonNull String query, @NonNull Class<? extends Searcher
try {
Constructor<? extends Searcher> constructor = searcherClass.getConstructor(ISearchActivity.class, String.class);
searcher = constructor.newInstance(this, query);
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
} catch (ReflectiveOperationException e) {
Log.e(TAG, "new <? extends Searcher>", e);
}
if (searcher != null)
Expand All @@ -1062,11 +1099,9 @@ public void clearSearchText() {
}

public void clearSearch() {
if (mSearchEditText == null)
return;

mSearchEditText.setText("");
clearSearchText();
clearAdapter();
updateClearButton();
}

public void refreshSearchRecords() {
Expand All @@ -1087,10 +1122,8 @@ private void showResultList(boolean animate) {
Log.d(TAG, "showResultList (anim " + animate + ")");
if (TBApplication.state().getResultListVisibility() != LauncherState.AnimatedVisibility.ANIM_TO_VISIBLE)
mResultLayout.animate().cancel();
if (mResultLayout.getVisibility() == View.VISIBLE)
return;

mResultLayout.setVisibility(View.VISIBLE);
Log.d(TAG, "mResultLayout set VISIBLE (anim " + animate + ")");
if (animate) {
TBApplication.state().setResultList(LauncherState.AnimatedVisibility.ANIM_TO_VISIBLE);
mResultLayout.setAlpha(0f);
Expand Down Expand Up @@ -1169,7 +1202,8 @@ private void updateSearchRecords(boolean isRefresh, @NonNull Searcher searcher)
dismissPopup();

TBApplication.runTask(getContext(), searcher);
showResultList(true);
boolean animate = !TBApplication.state().isResultListVisible();
showResultList(animate);
}

public void beforeLaunchOccurred() {
Expand Down Expand Up @@ -1556,6 +1590,17 @@ public void onNewIntent() {
ShortcutUtil.addShortcut(mTBLauncherActivity, intent);
return;
}
// Pasting shared text from Sharesheet via intent-filter into kiss search bar
if (Intent.ACTION_SEND.equals(action) && "text/plain".equals(intent.getType())) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
// making sure the shared text is not an empty string
if (sharedText != null && sharedText.trim().length() > 0) {
mSearchEditText.setText(sharedText);
return;
} else {
//Toast.makeText(this, R.string.shared_text_empty, Toast.LENGTH_SHORT).show();
}
}
}

executeButtonAction("button-home");
Expand Down Expand Up @@ -1590,14 +1635,14 @@ else if (TBApplication.state().isResultListVisible()) {
}
}

public void setActivityOrientation(@NonNull Activity act) {
if (mPref.getBoolean("lock-portrait", true)) {
if (mPref.getBoolean("sensor-orientation", true))
public static void setActivityOrientation(@NonNull Activity act, @NonNull SharedPreferences pref) {
if (pref.getBoolean("lock-portrait", true)) {
if (pref.getBoolean("sensor-orientation", true))
act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
else
act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT);
} else {
if (mPref.getBoolean("sensor-orientation", true))
if (pref.getBoolean("sensor-orientation", true))
act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
else
act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public class SettingsActivity extends AppCompatActivity implements PreferenceFra
"search-bar-height", "search-bar-text-size", "search-bar-radius", "search-bar-gradient", "search-bar-at-bottom",
"search-bar-argb", "search-bar-text-color", "search-bar-icon-color",
"search-bar-ripple-color", "search-bar-cursor-argb", "enable-suggestions-keyboard",
"lock-portrait", "sensor-orientation",
"search-bar-layout", "quick-list-position"
));
private final static ArraySet<String> PREF_LISTS_WITH_DEPENDENCY = new ArraySet<>(Arrays.asList(
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/rocks/tbog/tblauncher/TBApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ public static void resetTask(Context context) {
}
}

public static boolean hasSearchTask(Context context) {
TBApplication app = getApplication(context);
return app.mSearchTask != null;
}

public static IconsHandler iconsHandler(Context ctx) {
return getApplication(ctx).iconsHandler();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ protected void onCreate(Bundle savedInstanceState) {
* Initialize preferences
*/
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
//prefs = PreferenceManager.getDefaultSharedPreferences(this);
var prefs = PreferenceManager.getDefaultSharedPreferences(this);
Behaviour.setActivityOrientation(this, prefs);

/*
* Permission Manager
Expand Down Expand Up @@ -157,8 +158,6 @@ protected void onStart() {
Log.d(TAG, "onStart(" + this + ")");
super.onStart();

behaviour.setActivityOrientation(this);

if (DebugInfo.providerStatus(this)) {
debugTextView.setVisibility(View.VISIBLE);
}
Expand All @@ -178,8 +177,6 @@ protected void onStop() {
protected void onRestart() {
Log.d(TAG, "onRestart(" + this + ")");
super.onRestart();

behaviour.setActivityOrientation(this);
}

@Override
Expand Down
Loading

0 comments on commit 0b11a77

Please sign in to comment.