diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6cd4efb..116870d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,7 +15,8 @@ android:theme="@style/AppTheme"> + android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar" + android:windowSoftInputMode="adjustResize"> diff --git a/app/src/main/java/android/nachiketa/ebookdownloader/AndroidReadWrite.java b/app/src/main/java/android/nachiketa/ebookdownloader/AndroidReadWrite.java deleted file mode 100644 index b283e0e..0000000 --- a/app/src/main/java/android/nachiketa/ebookdownloader/AndroidReadWrite.java +++ /dev/null @@ -1,23 +0,0 @@ -package android.nachiketa.ebookdownloader; - -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.util.Scanner; - -public class AndroidReadWrite { - - public static String readFile(String path) { - StringBuilder builder = new StringBuilder(); - try { - Scanner scanner = new Scanner(new FileReader(path)); - while (scanner.hasNext()) { - builder.append(scanner.nextLine()); - } - scanner.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - return builder.toString(); - } - -} diff --git a/app/src/main/java/android/nachiketa/ebookdownloader/Global.java b/app/src/main/java/android/nachiketa/ebookdownloader/Global.java new file mode 100644 index 0000000..4713165 --- /dev/null +++ b/app/src/main/java/android/nachiketa/ebookdownloader/Global.java @@ -0,0 +1,25 @@ +package android.nachiketa.ebookdownloader; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Random; + +public class Global { + + public String getRandomQuote() throws IOException { + Random random = new Random(); + StringBuilder builder = new StringBuilder(); + InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("res/raw/quotes.txt"); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); + String line; + while ((line = bufferedReader.readLine()) != null) { + builder.append(line); + } + int randomNumber = random.nextInt(37); + String[] temp = builder.toString().split("~"); + return temp[randomNumber]; + } + +} diff --git a/app/src/main/java/android/nachiketa/ebookdownloader/MainActivity.java b/app/src/main/java/android/nachiketa/ebookdownloader/MainActivity.java index c1e73ec..45a9ff2 100644 --- a/app/src/main/java/android/nachiketa/ebookdownloader/MainActivity.java +++ b/app/src/main/java/android/nachiketa/ebookdownloader/MainActivity.java @@ -8,8 +8,12 @@ import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.EditText; +import android.widget.RadioButton; +import android.widget.TextView; import android.widget.Toast; +import java.io.IOException; + public class MainActivity extends AppCompatActivity { @Override @@ -18,30 +22,45 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,}, 1); + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); } + } + @Override + protected void onStart() { + super.onStart(); + TextView textView = findViewById(R.id.tvDisplay); + try { + textView.setText(new Global().getRandomQuote()); + } catch (IOException e) { + e.printStackTrace(); + } } public void execute(View view) { - EditText etBookName = (EditText) findViewById(R.id.etBookName); - EditText etAuthor = (EditText) findViewById(R.id.etAuthor); - - if (!etBookName.getText().toString().equals("")) { - if (!etAuthor.getText().toString().equals("")) { - Intent intent = new Intent(this, DownloadActivity.class); - intent.putExtra("bookName", etBookName.getText().toString()); - intent.putExtra("author", etAuthor.getText().toString()); - startActivity(intent); - } - else { - Toast.makeText(this, "Please enter name of the author", Toast.LENGTH_LONG).show(); - } - } - else { - Toast.makeText(this, "Please enter the book name", Toast.LENGTH_LONG).show(); + EditText etQuery = findViewById(R.id.etQuery); + RadioButton radBook = findViewById(R.id.radBookName); + RadioButton radAuthor = findViewById(R.id.radAuthor); + + if (!etQuery.getText().toString().equals("")) { + String choice; + if (radBook.isChecked()) + choice = "book"; + else + choice = "author"; + Intent intent = new Intent(this, DownloadActivity.class); + intent.putExtra("searchQuery", etQuery.getText().toString()); + intent.putExtra("searchBy", choice); + startActivity(intent); + } else { + Toast.makeText(this, "Woah! You gotta give me something to work with", Toast.LENGTH_LONG).show(); + etQuery.setFocusable(true); } } -} \ No newline at end of file +} + +// TODO : Change UI +// TODO : Add menu +// TODO : Optimize Libgen Parsing \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 6fc7cc0..ebec6d6 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -8,33 +8,49 @@ android:weightSum="4"> - + android:background="#FBF7D2" + android:orientation="horizontal" + android:weightSum="2"> + + + + + +