Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
xoureldeen committed Jul 16, 2024
1 parent b69c339 commit ab60149
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 74 deletions.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private boolean checkFreeSpace() {
}

private void showLowSpaceDialog() {
new AlertDialog.Builder(activity)
new AlertDialog.Builder(activity, R.style.MainDialogTheme)
.setTitle("Low Space Warning")
.setMessage("You do not have enough free space to continue.")
.setPositiveButton("Exit", (dialog, which) -> finish())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.vectras.boxvidra.adapters;

import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.system.ErrnoException;
import android.text.SpannableString;
import android.text.Spanned;
Expand All @@ -14,21 +14,27 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.switchmaterial.SwitchMaterial;
import com.vectras.boxvidra.R;
import com.vectras.boxvidra.activities.MainActivity;
import com.vectras.boxvidra.core.TermuxX11;
import com.vectras.boxvidra.fragments.HomeFragment;
import com.vectras.boxvidra.services.MainService;
import com.vectras.boxvidra.utils.BoxvidraUtils;
import com.vectras.boxvidra.utils.JsonUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class WinePrefixAdapter extends RecyclerView.Adapter<WinePrefixAdapter.ViewHolder> {
Expand All @@ -48,10 +54,76 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(view);
}

private boolean isMainServiceRunning() {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (MainService.class.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}

private void showOptionsDialog(ViewHolder holder, File winePrefix) {
View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_prefix_options, null);

SwitchMaterial switchWine64 = dialogView.findViewById(R.id.switchWine64);
SwitchMaterial switchStartXFCE4 = dialogView.findViewById(R.id.switchStartXFCE4);

// Load saved options if available
File optionsFile = new File(winePrefix, "options.json");
if (optionsFile.exists()) {
try {
JSONObject options = JsonUtils.loadOptionsFromJson(optionsFile);
switchWine64.setChecked(options.getBoolean("wine64"));
switchStartXFCE4.setChecked(options.getBoolean("startxfce4"));
} catch (IOException | JSONException e) {
e.printStackTrace();
}
}

AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.MainDialogTheme)
.setTitle("Choose Command")
.setView(dialogView)
.setPositiveButton("OK", (dialog, which) -> {
if (!switchWine64.isChecked() && !switchStartXFCE4.isChecked()) {
Toast.makeText(context, "At least one option must be enabled!", Toast.LENGTH_SHORT).show();
showOptionsDialog(holder, winePrefix);
} else {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("wine64", switchWine64.isChecked());
jsonObject.put("startxfce4", switchStartXFCE4.isChecked());

JsonUtils.saveOptionsToJson(optionsFile, jsonObject);
} catch (JSONException | IOException e) {
e.printStackTrace();
Toast.makeText(context, "Failed to save options!", Toast.LENGTH_SHORT).show();
}
}
})
.setNegativeButton("Cancel", null);

AlertDialog dialog = builder.create();
dialog.show();
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
File winePrefix = winePrefixes.get(position);
holder.textView.setText(winePrefix.getName());

boolean isServiceRunning = isMainServiceRunning();
holder.itemView.setEnabled(!isServiceRunning);
holder.menuButton.setEnabled(!isServiceRunning);

if (isServiceRunning) {
holder.itemView.setOnClickListener(null);
holder.itemView.setOnLongClickListener(null);
} else {
holder.itemView.setOnClickListener(holder);
holder.itemView.setOnLongClickListener(holder);
}
}

@Override
Expand All @@ -61,10 +133,19 @@ public int getItemCount() {

public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
TextView textView;
ImageButton menuButton;

public ViewHolder(@NonNull View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.TVTitle);
menuButton = itemView.findViewById(R.id.BTMenu);

menuButton.setOnClickListener(v -> {
int position = getAdapterPosition();
File winePrefix = winePrefixes.get(position);
showOptionsDialog(this, winePrefix);
});

itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
}
Expand Down Expand Up @@ -159,4 +240,4 @@ private void deleteDirectory(File dir) {
}
dir.delete();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.vectras.boxvidra.fragments;
import android.content.Intent;
import android.os.Bundle;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;

import com.termux.app.TermuxActivity;
import com.vectras.boxvidra.R;

public class OptionsFragment extends PreferenceFragmentCompat {
Expand All @@ -11,15 +13,17 @@ public class OptionsFragment extends PreferenceFragmentCompat {
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preferences, rootKey);

// Handle clicks on preferences
findPreference("key_environment").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
// Navigate to EnvironmentManagementFragment
navigateToEnvironmentManagementFragment();
return true;
}
findPreference("key_environment").setOnPreferenceClickListener(preference -> {
navigateToEnvironmentManagementFragment();
return true;
});

findPreference("key_terminal").setOnPreferenceClickListener(preference -> {
Intent intent = new Intent(getActivity(), TermuxActivity.class);
startActivity(intent);
return true;
});

}

private void navigateToEnvironmentManagementFragment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@
import com.termux.app.TermuxService;
import com.vectras.boxvidra.R;
import com.vectras.boxvidra.adapters.WinePrefixAdapter;
import com.vectras.boxvidra.utils.JsonUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -164,6 +169,18 @@ protected Boolean doInBackground(String... params) {
new File(prefixDir, "dosdevices").mkdirs();
new File(prefixDir, "dosdevices/c:").mkdirs();
new File(prefixDir, "dosdevices/d:").mkdirs();

// Create options.json with both options enabled
File optionsFile = new File(prefixDir, "options.json");
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("wine64", false);
jsonObject.put("startxfce4", true);
JsonUtils.saveOptionsToJson(optionsFile, jsonObject);
} catch (JSONException | IOException e) {
e.printStackTrace();
return false;
}
return true;
} else {
return false;
Expand All @@ -182,4 +199,12 @@ protected void onPostExecute(Boolean success) {
}
}
}

@Override
public void onResume() {
super.onResume();
loadWinePrefixes();
adapter.notifyDataSetChanged();
}

}
Loading

0 comments on commit ab60149

Please sign in to comment.